vb.net/DataGridView/ComboBoxCell? [英] vb.net / DataGridView / ComboBoxCell?

查看:129
本文介绍了vb.net/DataGridView/ComboBoxCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb.net 2010,winforms和DataGridView。

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

DataGridView有一个DataGridViewComboBox列。当我显示带有DGV的表单时,它显示了这个空白的网格,但是包含ComboBox的列显示了下拉列表中的第一项。

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.

如何使ComboBox在单击和选择之前什么也不显示?

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

推荐答案

尝试在初始化时将combobox selectedindex属性设置为-1。这也许可以解决您的问题,但是当我执行您描述的相同操作时,我的组合框中的所有值都不会显示,直到我单击它为止。这是我采取的步骤:

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

现在,您的控件应该表现出您的行为问。我运行它时效果很好。如果不是,那可能是因为我正在运行VS2008,所以是VS2010的错误。

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.

在代码中添加项目时,只需将组合框值设置为Nothing:

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"})

这篇关于vb.net/DataGridView/ComboBoxCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆