如何防止datagridviewcomboboxcolumn选择索引发生变化?

时间:2015-06-24 07:09:54

标签: c# datagridview datagridviewcombobox datagridviewcomboboxcell

我正在使用

datagridview,

因为我正在使用

datagridviewcomboboxcolumn.

此datagridview中有三行,因此在datagridviewcomboboxcolumn中的每一行中都创建了三个组合框。

这些combox具有相同的项目,但每个项目的选定索引不同。 例如:假设有三个项目A,B和C.第一个组合框选择的项目是A,第二个有B,第三个有C,所以选择的索引分别是0,1和2。

现在,我正在这样做,

DataTable dt_Groupingdetails;
//Grouping details have changed values Z,B,C for that column(comboboxcolumn).
List<string> list_groups = new List<string>();    

this.gView_cBoxgroup.DataSource =  className.GetChangedValues();

public static List<string> GetChangedValues()
{
foreach (DataRow drow in dt_Groupingdetails.Rows)                 
list_groups.Add(drow["comboboxcolumn"].ToString());
return list_groups;
}   

当我更改DataSource时,每个组合框的选定索引也更改为0.但我不想更改索引。我想只更新每行的索引项。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

解决方法是在更改DataSource之前将所选索引保留在临时变量中,然后在DataSource更改后使用temp变量设置ComboBox列的选定索引。

相关问题