What is The difference Between ColumnCount and Columns.Count in DataGridView

I am using datagridview for a lot of things and I think it's a really strong data viewer tool. My Problem is, I am using this code:

for (int i = 0; i < dataGridView1.**Columns.Count** - 1; i++)
{
  ....                
}

My question is, what is the difference between dataGridView1.Columns.Count and dataGridView1.ColumnCount.

They both return an integer that holds the number of columns in the dataGridView1 I searched only but couldn't find anything. I hope you guy help me.

Upvotes: 2

Views: 758

Answers (1)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186833

If we consult reference source

https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/DataGridView.cs,84e79a2ba1ae9635,references

we'll see no difference with respect of get accessor:

    public int ColumnCount
    {
        get
        {
            return this.Columns.Count;
        }
        set
        {
            ...
        }
    }

It seems DataGridView.ColumnCount property has been designed in order to provide set in which we can add / remove columns

Upvotes: 2

Related Questions