First of all, I must mention that I have seen this question, but it didn't help me to fix my problem.
According to my previous question, I saved my DataGridView
to an XML file. Now I am going to fill the DataGridView
when I load the window form using the data stored on the XML file.
My problem is that when I want to set the value of one ComboBox
based on the stored data, the other ComboBox
's value changes too. I want to set each ComboBox
's value separately.
My code is as follows :
private void WindowSelection_Load(object sender, EventArgs e)
{
dataGridSource = DeserializeFromXML();
foreach (WindowHolder obj in dataGridSource)
{
int index = dataGridViewWindowSelection.Rows.Add();
DataGridViewComboBoxColumn combo2 = new DataGridViewComboBoxColumn();
combo2 = (DataGridViewComboBoxColumn)dataGridViewWindowSelection.Rows[index].Cells["Reader"].OwningColumn;
combo2.DataSource = readerSource;
int readerSourceIndex = findReaderSourceIndex(obj.reader);
if (readerSourceIndex != -1)
{
combo2.DefaultCellStyle.NullValue = readerSource[readerSourceIndex];
}
else
{
combo2.DefaultCellStyle.NullValue = readerSource[0];
}
dataGridViewWindowSelection.Rows[index].Cells["Location"].Value = obj.location;
dataGridViewWindowSelection.Rows[index].Cells["AlwaysOnTop"].Value = obj.alwaysOnTop;
dataGridViewWindowSelection.Rows[index].Cells["AlwaysShow"].Value = obj.alwaysShow;
}
}