0

我有DataGridView两列定义如下:

Dim col As New DataGridViewColumn
col.DefaultCellStyle.BackColor = Color.FromArgb(&HFFAAAAAA)
col.Name = "Description"
col.MinimumWidth = 80
col.DataPropertyName = "Description"
col.ValueType = GetType(String)
col.ReadOnly = True
col.CellTemplate = New DataGridViewTextBoxCell
S0Grid.Columns.Add(col)

col = New DataGridViewColumn
col.DefaultCellStyle.BackColor = Color.FromArgb(&HFFBBBBBB)
col.Name = "Value"
col.MinimumWidth = 80
col.DataPropertyName = "Value"
col.ValueType = GetType(String)
col.CellTemplate = New DataGridViewTextBoxCell
S0Grid.Columns.Add(col)

我需要位置 Col=1, Row=0 的单元格是 aComboBox而不是 a TextBox。所以我尝试添加以下代码但它不起作用,编辑控件仍然是一个文本框。

Dim cbCell As New
DataGridViewComboBoxCell
cbCell.Items.AddRange([Enum].GetNames(GetType(System.Reflection.BindingFlags)))
S0Grid(1, 0) = cbCell

你知道我该如何解决这个问题吗?

4

1 回答 1

0

该代码应该可以工作,是否有可能没有被调用或抛出或类似的?

试试这个代码:

Dim cbCell As New DataGridViewComboBoxCell
S0Grid(1, 0) = cbCell
MessageBox.Show("Test")

看到消息框了吗?你现在看到组合了吗?

于 2010-06-21T13:35:07.163 回答