gruber
gruber

Reputation: 29759

Binding entity framework winfoms

I am using Entity Framework as a Model and WinForms as a View.

I have one combobox with Car Company and listBox with car models.

I created two BindingSources: CompanyBindingSource and ModelBindingSource.

Then when I run application I set datasources for my BindingSources corresponding to my logic.

And it works great I have as datasource all models and companies but I would also like to have functionality that when I change Company in combobox, DataSource for listBox should contain only models from that company.

Is it possible to make it automatically ?

thanks for any help, bye

Upvotes: 1

Views: 568

Answers (1)

Tom
Tom

Reputation: 3374

You might potentially be better off arranging your data into a single BindingSource, using hierarchical data so your Company contains a list of Models applicable to it.

This way, you'd bind your first combo to the datasource, and the second combo would cascade the Models property of the chosen Company.

Alternatively, catch the SelectedIndexChanged event and set a Filter for the ModelBindingSource entities.

Upvotes: 1

Related Questions