2

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.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215

1 Answers1

2

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

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215