Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using vb.net 2010 and winforms and DataGridView.

The DataGridView has a DataGridViewComboBox column. When I show the form with the DGV it shows this and empty grid but the column that contains the ComboBox shows the first item on the dropdown list.

How can I have the ComboBox display nothing until it is clicked on and selected?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
308 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try setting the combobox selectedindex property to -1 when you initialize it. That might fix your problem, but when I do the same thing that you described, mine doesn't show any values in the combobox until I click on it. Here are the steps I took:

1. create a datagridview control.

2. right click on control and add column.

3. add DataGridViewComboBoxColumn

4. right click on control and edit columns.

5. Click on the button for "Items (Collection)".

6. Add some items

Now your control should behave how you are asking. It works fine when I run it. If it doesn't it may be a VS2010 bug since I'm running VS2008.

Edit:

When you add your items in code, just set the combobox value to Nothing:

Dim cboBrand As New DataGridViewComboBoxColumn
With cboBrand
    .HeaderText = "Brand"
    .Name = "Brand"
    .Width = 300
    .Items.Add("item1")
    .Items.Add("item2")
    .Items.Add("item3")
End With

Me.DataGridView1.Columns.Insert(0, cboBrand)
DataGridView1.Rows.Insert(0, New Object() {Nothing})

or if you want to set an initial value, do it like this:

DataGridView1.Rows.Insert(0, New Object() {"item2"})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...