开发者

How to set a single ComboBoxCell in a TextBoxCell column of DataGridView?

开发者 https://www.devze.com 2023-01-04 00:21 出处:网络
I have a DataGridView with two columns defined like: Dim col As New DataGridViewColumn col.DefaultCellStyle.BackColor = Color.FromArgb(&HFFAAAAAA)

I have a DataGridView with two columns defined like:

Dim col As New DataGridViewColumn
col.DefaultCellStyle.BackColor = Color.FromArgb(&HFFAAAAAA)
col.Name = "Description"
col.MinimumW开发者_Go百科idth = 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)

I need that the cell in position Col=1, Row=0 is a ComboBox and not a TextBox. So I tried to add the following code but it does not work, the edit control remains a TextBox.

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

Do you know how can I solve this issue?


That code should work, is it possible that it's not getting called or that it throws or similar?

Try this code:

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

Do you see the messagebox? And do you see the combo now?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号