gosonic
asked on
vb.net - Adding Item To Combo box collection
I'm trying to add an item ("<Select Item"> ) to a combo box in the load_gnder sub below.
I've tried "'Me.cbogender.Items.Inser t(0, "<Select One>")" which runs but wont display - and severl other ways to add the item but I cant get it to display in the combo box.
Thanks
[code]
Private Sub load_gender()
Dim Dsgender As New DataSet
Dim Sqlgender As String = ("select Description,indx from gender")
Dsgender = get_data(Sqlgender)
Dim dvgen As DataView = Dsgender.Tables(0).Default View
Me.cbogender.DataSource = dvgen
Me.cbogender.DisplayMember = ("Description")
Me.cbogender.ValueMember = ("indx")
End Sub
Public Function get_data(ByVal Sqlin As String) As DataSet
Dim Sqldata As String = Sqlin
Dim conn As New SqlCeConnection(connstr)
Dim DA1 As SqlCeDataAdapter = New SqlCeDataAdapter(Sqldata, conn)
Dim ds4 = New DataSet
DA1.Fill(ds4, "Table1")
conn.Dispose()
Return ds4
End Function
[/code]
I've tried "'Me.cbogender.Items.Inser
Thanks
[code]
Private Sub load_gender()
Dim Dsgender As New DataSet
Dim Sqlgender As String = ("select Description,indx from gender")
Dsgender = get_data(Sqlgender)
Dim dvgen As DataView = Dsgender.Tables(0).Default
Me.cbogender.DataSource = dvgen
Me.cbogender.DisplayMember
Me.cbogender.ValueMember = ("indx")
End Sub
Public Function get_data(ByVal Sqlin As String) As DataSet
Dim Sqldata As String = Sqlin
Dim conn As New SqlCeConnection(connstr)
Dim DA1 As SqlCeDataAdapter = New SqlCeDataAdapter(Sqldata, conn)
Dim ds4 = New DataSet
DA1.Fill(ds4, "Table1")
conn.Dispose()
Return ds4
End Function
[/code]
You can't add items in that fashion to a databound control. You need to "manually" populate the control and then include your extra item.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
roger
I really dont want to ad it to the DB table. You solution should work.
Thanks
I really dont want to ad it to the DB table. You solution should work.
Thanks