【发布时间】:2012-01-04 15:04:13
【问题描述】:
首先,我必须提到我见过this question,但这并没有帮助我解决我的问题。
根据我的previous question,我将我的DataGridView 保存到了一个XML 文件中。现在,当我使用存储在 XML 文件中的数据加载窗口窗体时,我将填写 DataGridView。
我的问题是,当我想根据存储的数据设置一个ComboBox 的值时,另一个ComboBox 的值也会发生变化。我想分别设置每个ComboBox 的值。
我的代码如下:
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;
}
}
【问题讨论】: