1
votes

I am having trouble using a bindingsource to select an item in a combobox. I populate the combobox no problem, the items are listed. I double checked that my binding source contains information.

Combobox has a displaymember (text) and valuemember(integer)

my bindingsource contains the valuemember.

How do i bind the combobox to bindingsource so it shows the correct displaymemeber based on the valuemember stored in bindingsource.

this is what i have tried

cboAccessLevel.SelectedValue = EditMembershipBindingSource("accesslevelid")

I am using vb.net

here is bindingcode

        strSQL = "select * from memberships where name = " & "'" & MembershipName & "'"

        Using Connection As New SqlConnection(ProgramSQLConnection)
            Connection.Open()
            Dim Command As New SqlClient.SqlCommand(strSQL, Connection)
            Dim MyAdapter As SqlDataAdapter = New SqlDataAdapter
            MyAdapter.SelectCommand = Command
            dtSpecificMembership = New DataTable
            MyAdapter.Fill(dtSpecificMembership)
            EditMembershipBindingSource.DataSource = dtSpecificMembership
            Connection.Close()
        End Using
3
Show binding code as well. - dotNET

3 Answers

0
votes
cboAccessLevel.DataTextField = displayMember
cboAccessLevel.DataValueField = valuemember

If I understand your question correctly ...

0
votes

This is what worked for me:

cboAccessLevel.DataBindings.Add("Selectedvalue", EditMembershipBindingSource, "accesslevelid")
0
votes

Hai add your BindingSource with Onedataset and TableAdapter and using Combobox Use Bound data items options tick and select your datasource and choose your bindingsource and value member and display member