I got two different Datagridviews. Datagridview2 has just text columns. Datagridview1 contains mostly text columns and one DatagridviewComboBoxColumn. The comboxbox contains a list of all values from one column in Datagridview2. I want to update each comboboxcell everytime Datagridview2 changes. I’ve a read and tried a lot but i still haven’t found a way how i can change the values of a DatagridviewComboboxcell during runtime with content from another Datagridview.
To make things a bit more clear, here is a little code-snippet of how i want to change the content on a specific event (this code don’t work)
var cls = new List<string>();
if (dataGridView2.Rows.Count > 0)
{
for (int rows = 0; rows < dataGridView2.Rows.Count; rows++)
{
if (dataGridView2[0, rows].Value != null)
{
cls.Add(dataGridView2[0, rows].Value.ToString());
}
}
for (int rows = 0; rows < dataGridView1.Rows.Count; rows++)
{
DataGridViewComboBoxCell cl = new DataGridViewComboBoxCell();
var cl_content = cls;
cl.DataSource = cl_content;
var cell = dataGridView1[1, rows] as DataGridViewComboBoxCell;
cell.DataSource = cl;
}
}
I’ve tried some ideas from another post
but nothing worked.