Drilldown comboboxes

Ultrawhack

Well-known member
Joined
Jul 5, 2006
Messages
164
Location
Canada
Programming Experience
3-5
I have 3 tables tblCountry, tblState, tblCity with CountryID & StateID as relational fields.

when a user selects from cboCountry CountryID filters the content of cboState
when a user selects from cboState StateID filters the content of cboCity

I need help with the filtering code please for these drilldown comboboxes.

Thanks !
 
There is no code required. If you setup your data-bindings properly it will all be done for you. Add a DataSet to your form. Add the three DataTables to your DataSet. Add the two DataRelations to your DataSet. Add three BindingSources to your form. Bind the Contry table to one BindingSource and the appropriate relationships to the other two. Bind the three BindingSources to three ComboBoxes. Done! The controls will filter themselves. This may sound complex but with know-how it would take about three minutes to set up. The only way to get that know-how is to do.

Having said all that, if you really want to use code to accomplish the filtering then you can bind the DataTables directly to the ComboBoxes. When the SelectedIndex of the Country ComboBox changes you would set the DefaultView.RowFilter property of the State DataTable. Likewise for the State and City. You could also bind the DataTables to BindingSources,bind the BindingSources to the ComboBoxes and then set the Filter properties of the BindingSources.
 
Thanks very much. I went with your option 1 and added the datasource, datatables and set the datarelations.

In the data Source window I changed the country, state & city datatable fields to combobox and then dragged it onto my form.

The binding sources were automatically created and it seemed to work fine until I tried to close the form.

I then get an error from codeline
components.Dispose();
Cannot bind to the property or column Country on the DataSource.
Parameter name: dataMember


Any ideas on what I may be doing wrong ?
 
It's hard to say but I would guess that the BindingSources are being destroyed before the ComboBoxes, leaving the controls pointing to invalid data sources. I'd try rearranging the designer code to see if that can sort the issue but if you do that be VERY careful what you change because you may render the form unusable if you change the wrong thing.
 
OK, I was able to find the culprit. I have included steps to reconstruct the error I am getting while databinding an access database and trying to get the combobox to autocomplete.
  • I added the datasource using Data | Add new datasource.
  • From the datasource window I changed the field to combobox and dragdropped the combobox onto my form.
  • Using combobox tasks, I used databinding and set the combobox's data source, display member and value member.
  • From combobox properties I set autocomplete mode to Suggest. I set autocompletesource to ListItems
I then get the above mentioned components.dispose error. If autocomplete mode is set to None this error does not occur.

Any wisdom ?
 
Back
Top