【问题标题】:How to prevent datagridviewcomboboxcolumn selected index to change?如何防止datagridviewcomboboxcolumn选择的索引改变?
【发布时间】:2015-06-24 07:09:53
【问题描述】:

我正在使用一个

datagridview,

因为我正在使用一个

datagridviewcomboboxcolumn.

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

这些组合框具有相同的项目,但每个项目的选定索引不同。 例如:假设有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。但我不想更改索引。我只想更新每一行的索引项。

我该怎么做?

【问题讨论】:

    标签: c# datagridview datagridviewcombobox datagridviewcomboboxcell


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多