我有一个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的单元格是ComboBox
而不是TextBox
。所以我尝试添加以下代码,但它不起作用,编辑控件仍然是TextBox。
Dim cbCell As New
DataGridViewComboBoxCell
cbCell.Items.AddRange([Enum].GetNames(GetType(System.Reflection.BindingFlags)))
S0Grid(1, 0) = cbCell
您知道我该如何解决这个问题吗?
答案 0 :(得分:0)
该代码应该有效,是否可能没有被调用或抛出或类似?
试试这段代码:
Dim cbCell As New DataGridViewComboBoxCell
S0Grid(1, 0) = cbCell
MessageBox.Show("Test")
你看到了消息框吗?你现在看到组合了吗?