如何在DataGridView中的ComboBox列的下一行中添加不同的数据
问题描述:
我想在 DataGridView
ComboBox
列中添加一些值,但是
例如 - 第一行数据将在 ComboBox
栏中 abcd 栏目
2nd行中的数据将是 abcdefg 在 ComboBox
列
表示我想要不同行中的不同项目在同一 ComboBox
列。
I want to add some values in DataGridView
ComboBox
column, but
for example- 1st row the data will "abcd" in ComboBox
Column
2nd row the data will be "abcdefg" in ComboBox
Column
means I want different items in different rows on same ComboBox
Column.
答
如何添加第一行然后更新项目在ComboBoxColumn中
how about add first the row then update the items in the ComboBoxColumn
Dim dtgCol As DataGridViewComboBoxCell
Dim row As String()
row = New String() {"0", "1"}
dtgView.Rows.Add(row)
dtgCol = dtgView.Rows(0).Cells(2)
dtgCol.Items.Add("comboitem1")
dtgCol.Items.Add("comboitem2")
row = New String() {"2", "3"}
dtgView.Rows.Add(row)
dtgCol = dtgView.Rows(0).Cells(2)
dtgCol.Items.Add("comboitem1")
dtgCol.Items.Add("comboitem2")
dtgCol.Items.Add("comboitem3")
这只是我的想法..我已经完成了...希望这有帮助
this is just my idea.. I already done this... hope this helps
只需在每一行中添加新的组合框单元格
Simply add new comboBox Cell in every row
DataGridViewComboBoxCell dgvCmbCell;
dgvCmbCell = (DataGridViewComboBoxCell)myGrid.Rows[rowInx].Cells[colInx];
dgvCmbCell.Items.Clear();
dgvCmbCell.Value = null;
//And make your loop
while (...)
{
dgvCmbCell.Items.Add(.....);
}
我相信它会达到您的要求;
I believe it will reach your requirement;