4

I need to populate a .net DataGridView from a collection physically (without data binding) in C#. That is, I should use foreach loops and iterate through the collection while creating a row for each object and a cell for each property.

I have created the columns in design mode. Now I need to create rows dynamically.

How to do that?

Rémi
  • 3,867
  • 5
  • 28
  • 44
user366312
  • 16,949
  • 65
  • 235
  • 452

1 Answers1

5

Add an array of objects, the number of which should correspond to the number of columns.

e.g.

this.datagridview1.Rows.Add(new object[] { "col1", "col2", "col3", 4.5, true});

Ian
  • 33,605
  • 26
  • 118
  • 198