C # - How to programmatically populate a .net DataGridView?

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

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

How to do it?

+3
source share
1 answer

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

eg.

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

+3
source

Source: https://habr.com/ru/post/1711796/


All Articles