I've two listbox-elements in my form. The items in listbox1 are representing the columns in my DataGridView, the items in my listbox2 are representing the rows in my DataGridView.
foreach (var el in listBox1Elements)
{
// code...
dataGridView1.Columns.Add(col);
}
Since items in listbox1 can be added or deleted I've a problem with my current solution.
dataGridView1.Rows.Add("test","some","data","even","more","data");
I wonder if there is a solution for using a List. Then my code could look something like this:
foreach (var el in listBox2Elements)
{
myList.add("some text");
}
dataGridView1.Rows.Add(myList);
Something like
foreach (var el in listBox2Elements)
myList.add("some text");
foreach (var item in myList)
dataGridView1.Rows.Add(item.., item.., item..);
or
dataGridView1.DataSource = myList.ToList()
How about:
foreach (var el in listBox2Elements)
{
myList.add("some text");
}
dataGridView1.Rows.Add(myList.ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With