I’m not actually sure how to ask the question so here’s what I’m doing:
I have a datacontext that im using via LINQ to SQL
linqDatabaseDataContext db = new linqDatabaseDataContext();
I have a combo box with a bunch of values that i use to populate a custom listbox using the combobox value as a filter by calling this method. i pass the string from the combobox into the method
private void PopulateList(string filter)
{
MessageBox.Show(filter);
var holds =
from a in db.Record_HoldDatas
join techs in db.LUT_Employees on a.LabTech equals techs.ID
join qaSups in db.LUT_Employees on a.QASupervisor equals qaSups.ID
join prodSups in db.LUT_Employees on a.ProductionSupervisor equals prodSups.ID
join flavors in db.LUT_Flavors on a.Flavor equals flavors.ID
where a.HoldStatus == filter
orderby a.HoldID descending
select new
{
a,
QASupervisor = qaSups.firstName + " " + qaSups.lastName,
ProdSupervisor = prodSups.firstName + " " + prodSups.lastName,
Tech = techs.firstName + " " + techs.lastName,
Headline = a.HoldID + " : " + a.Package + " " + flavors.flavor,
Flavor = flavors.flavor,
Status = a.HoldStatus
};
lbxHoldsList.ItemsSource = holds;
}
I want it to happen on selecteditem change of course. I know theres a way to do it through binding of an observable collection, but im at a loss of how to do it, im pretty new. The datacontext is pretty specific on the structure which is why I used the implicit type. Would anyone be willing to sort of push me in the right direction here?
If you are using MVVM:
Add a(n observable)collection of filters to the ViewModel, add a property to the ViewModel name SelectedFilter. Bind the SelectedFilter to the SelectedItem property of the ComboBox.
Add a handler in the ViewModel that is called when the SelectedFilter changes. In the handler call the Populate method.