Link to home
Start Free TrialLog in
Avatar of gosonic
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.Insert(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).DefaultView
        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]
Avatar of mastoo
mastoo
Flag of United States of America image

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
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gosonic
gosonic

ASKER

roger

I really dont want to ad it to the DB table. You solution should work.  
Thanks