2010-06-21 48 views
0

我有两列的DataGridView像定义:如何在DataGridView的TextBoxCell列中设置单个ComboBoxCell?

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) 

我需要在位置列= 1,行= 0的小区是ComboBox,而不是一个TextBox。所以我试图添加下面的代码,但它不起作用,编辑控件仍然是一个TextBox。

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

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

回答

0

该代码应该工作,它可能没有被调用,或者它抛出或类似?

试试这个代码:

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

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

+0

感谢您的关注。我验证并执行了代码,也许其他一些设置会干扰我的实现。我会做额外的检查 – Drake 2010-06-22 07:52:44

相关问题