Reputation: 121
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
Upvotes: 1
Views: 727
Reputation: 2566
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
Upvotes: 0
Reputation: 121
This is what worked for me:
cboAccessLevel.DataBindings.Add("Selectedvalue", EditMembershipBindingSource, "accesslevelid")
Upvotes: 0
Reputation: 389
cboAccessLevel.DataTextField = displayMember
cboAccessLevel.DataValueField = valuemember
If I understand your question correctly ...
Upvotes: 0