【发布时间】:2015-10-30 09:50:26
【问题描述】:
我定义了一个 XtraGrid GridControl,其中包含 3 列、2 个数据绑定和一个我已设置为 RepositoryItemComboBox 的列。该列的设置如下:
this.gridColumn3.Caption = "Test";
this.gridColumn3.FieldName = "test";
this.gridColumn3.Name = "gridColumn3";
this.gridColumn3.UnboundType = DevExpress.Data.UnboundColumnType.String;
this.gridColumn3.Visible = true;
this.gridColumn3.VisibleIndex = 2;
RepositoryItemComboBox 的创建方式如下:
RepositoryItemComboBox cbo = new RepositoryItemComboBox();
cbo.Items.Add("1");
cbo.Items.Add("2");
cbo.Items.Add("3");
cbo.Items.Add("4");
cbo.Items.Add("5");
cbo.Items.Add("6");
cbo.Items.Add("7");
gridView1.Columns[3].ColumnEdit = cbo;
查看网格时,combobox 完全按照我的意愿显示。尝试检索在combobox 中选择的值时会出现此问题。当按下网格外的button 时,应处理combobox 值。我使用以下代码:
for (int i = 0; i < gridView1.DataRowCount; i++)
{
int ID = (int)gridView1.GetRowCellValue(i, "id");
string Test = gridView1.GetRowCellValue(i, "test").ToString();
ProcessCombo(ID, Test);
}
在上面的代码中ID按预期检索,但gridView1.GetRowCellValue(i, "test")返回null。我可能错过了什么?这甚至是解决这个问题的正确方法吗?
【问题讨论】:
-
如果出现您将列设置为未绑定列,在这种情况下,需要处理 GridView 的 CustomUnboundColumnData 事件以便为单元格提供值。
-
我已经看过了,但是如何访问 CustomUnboundColumnData 事件中组合框的值?
标签: c# combobox devexpress xtragrid