【发布时间】:2017-08-27 04:28:46
【问题描述】:
我正在尝试用 winforms 中的组合框单元填充 datagridview 组合框列,其中每一行都有一个从字典中的嵌套列表派生的不同集合,当我迭代它并获取它的对象及其字符串值时,字典工作正常,但是,我在表单加载时用尽了每种不同的组合来填充组合框单元格都失败了。可能吗?我发现他们使用 cellclick 事件等的其他帖子。我更喜欢在表单初始化时填充。
//this works
public void create datatable()
{
DataGridViewComboBoxColumn Data_CmBx_Col_ObjectType = new DataGridViewComboBoxColumn();
Data_CmBx_Col_FamilyType.Name = _ADD_OBJECT_TYPE;
Data_CmBx_Col_FamilyType.HeaderText = _ADD_OBJECT_TYPE;
dataGridView.Columns.Insert(6, Data_CmBx_Col_ObjectType);
//pop combobox, the dictionary works
int i = 0;
foreach (KeyValuePair<object, List<objectType>> objectAndType in combined_Dictionary)
{
i++;
if (rowIndex <= combined_Dictionary.Count)
{
CreateCustomComboBoxDataSouce(i, objectAndType.Value);
}
}
//Bind dataGridView to a datatable
dataGridView_Family.DataSource = data;
}//end method
//method is called and fails with index out of range error collection
private void CreateCustomComboBoxDataSouce(int row, List<objectAndType> type) //row index ,and two parameters
{
DataGridViewComboBoxCell comboCell = dataGridView_objectAndType[6, row] as DataGridViewComboBoxCell;
comboCell.DataSource = new BindingSource(type, null);
}//end method
【问题讨论】:
-
注意:它在创建组合框单元的行上出错
标签: c# winforms indexoutofboundsexception datagridcomboboxcolumn datagridviewcomboboxcell