我在标签页中有datagridview。 datagridview有6列。第6列是组合柱。我正在尝试将数据源绑定到组合框。每行将根据行号具有不同的数据源。 datagridview总是有10行。问题是组合框没有填充任何值。它只是给我空白项目。如果我保留断点,datagrid和comboboxcolumn数据源都会显示数据表值。有人可以告诉我这里缺少什么吗?
private void BuildFreshAccessMatrix()
{
dataGridView1.AutoGenerateColumns = false;
DataGridViewComboBoxColumn cboPermissionCol = (DataGridViewComboBoxColumn)dataGridView1.Columns[5];
//cboPermissionCol.DataPropertyName = "UserLevelCategoryName";
dataGridView1.DataSource = dataProvider.GetBlankMatrixData();
int i = 1;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewComboBoxCell cboPermission = (DataGridViewComboBoxCell)(row.Cells["UserLevelCategoryNameAdd"]);
cboPermission.DataSource = dataProvider.GetPermissionComboData(i);
cboPermission.DisplayMember = "UserLevelCategoryName";
cboPermission.ValueMember = "UserLevelCategoryName";
i += 1;
}
}
答案 0 :(得分:0)
尝试将您的代码更改为:
DataGridViewComboBoxCell cboPermission = (DataGridViewComboBoxCell)
dataGridView1.Rows[i].Cells["UserLevelCategoryNameAdd"];
而不是:
DataGridViewComboBoxCell cboPermission = (DataGridViewComboBoxCell)
(row.Cells["UserLevelCategoryNameAdd"]);