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?

1 Answer 1

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});

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.