How far is the code for best functionallity? I have two ComboBox, so the first is related for choose the company, and the second for choose the branch-office in relation with the one.
I note that the only way I can fill datasource with filtering .Where on LINQ is on this way, maybe Im wrong please take a moment for look the following snippet :
private void cboCompany_SelectedIndexChanged(object sender, EventArgs e)
{
var _index = ((ComboBox)sender).SelectedIndex;
using (DB db = new DB())
{
var su = (from s in db.Branchs select s);
if (cboCompany.SelectedIndex == 0)
{
cboBranch.DataSource = su.Where(x => x.codeCompany == 1).Select(x => x.name).ToList();
}
else if (cboCompany.SelectedIndex == 1)
{
cboBranch.DataSource = su.Where(x => x.codeCompany == 2).Select(x => x.name).ToList();
}
cboBranch.BindingContext = this.BindingContext;
cboBranch.DisplayMember = "name";
cboBranch.SelectedIndex = 0;
}
}
Thanks in Advance!