开发者

Setting first field in a combo box to null

开发者 https://www.devze.com 2023-04-09 14:30 出处:网络
I have a databound ComboBox on my form. Is there any way that I can make the first field blank. I can do开发者_如何学编程 this with a DropDownList in the HTML part of .Net but is there a way to do i

I have a databound ComboBox on my form. Is there any way that I can make the first field blank.

I can do开发者_如何学编程 this with a DropDownList in the HTML part of .Net but is there a way to do it for a ComboBox?

Thanks


This is the code I used to overcome the problem...

ComboBox1.SelectedValue = -1


ComboBox1.SelectedValue = -1 

didn't work for me but this did:

ComboBox1.SelectedIndex = -1 

I would have though -1 would have been an invalid index value, but obviously not.

Kristian


You can insert a blank entry into data source.

Public Class Data
 Public Property No() As Integer
 Public Property Name() As String
End Class

and List(of Data),

Dim mlist As New List(Of Data)() From
    {
        New Data() With {.Name = "", .No = 0},
        New Data() With {.Name = "One", .No = 1},
        New Data() With {.Name = "Two", .No = 2}
    }

ComboBox1.DataSource = mlist
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "No"
0

精彩评论

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

关注公众号