Question Fill two combobox from datasource using databinding

Mimosa777

Active member
Joined
Aug 28, 2014
Messages
28
Programming Experience
1-3
Hi everyone,

I have a button and when clicked, open a panel with 2 combobox on a form. Depending on the selection of the first combobox (which is filled via a bindingsource) , ill be able to select the value I need on the second combobox. and here is my code for that :
VB.NET:
Private Sub btnSearchFacture_Main_Click(sender As Object, e As EventArgs) Handles btnSearchFacture_Main.Click
        PanelAddFacture.Visible = True
        'Fill Name Combobox
        With NameComboBox
            .DataSource = TblCustomersBindingSource
            .DisplayMember = "FirstName"
            .ValueMember = "FirstName"
            .AutoCompleteMode = AutoCompleteMode.SuggestAppend
            .AutoCompleteSource = AutoCompleteSource.ListItems
        End With
        With MarqueComboBox
            .DataSource = TblCarsBindingSource.Filter = "Customer_ID = " + TblCustomersBindingSource.Current("ID").ToString
            .DisplayMember = "Marque"
            .ValueMember = "Marque"
            .AutoCompleteMode = AutoCompleteMode.SuggestAppend
            .AutoCompleteSource = AutoCompleteSource.ListItems
        End With
End Sub

however, as soon as I click on the button, this is the error im getting :
[An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
Additional information: Complex DataBinding accepts as a data source either an IList or an IListSource.

I look everywhere for that type of error but still not able to understand what im doing wrong in my code. Any help please would be appreciated.

Thank you :encouragement:
 
This line:
.DataSource = TblCarsBindingSource.Filter = "Customer_ID = " + TblCustomersBindingSource.Current("ID").ToString
doesn't do anything like what you think it does. What it's actually doing is comparing the value of the TblCarsBindingSource.Filter property to the value of the String "Customer_ID = " + TblCustomersBindingSource.Current("ID").ToString to see if they are equal and then assigning the resulting Boolean value to the DataSource. Absolutely not what you want.

What you should be doing is setting up parent/child data-binding and letting the system handle the filtering for you. Learn how here:

Master/Detail (Parent/Child) Data-binding
 
yes :welcoming: I never tought ill enjoy coding in vb net as im doing right now. Lots of resources available to help switch from vba to vb and experts like you to guide me onto the right path.
 
Back
Top