private void comboState_SelectedIndexChanged(object sender, EventArgs e) { _selectedState = MessageRegions.States.FirstOrDefault(x => x.Name == comboState.Text); if (_selectedState != null) { comboCounty.Items.Clear(); comboCounty.Text = ""; _selectedCounty = null; foreach ( var thisCounty in MessageRegions.Counties.Where(x => x.state.Id == _selectedState.Id).OrderBy(x => x.Name)) { comboCounty.Items.Add(thisCounty.Name); } } }
public SAMERegion(SAMEState state, SAMECounty county) { State = state; County = county; }
private void comboCounty_SelectedIndexChanged(object sender, EventArgs e) { _selectedCounty = MessageRegions.Counties.FirstOrDefault( x => x.state.Id == _selectedState.Id && x.Name == comboCounty.Text); }
private void btnAddRegion_Click(object sender, EventArgs e) { if (comboState.SelectedIndex >= 0 && comboCounty.SelectedIndex >= 0 && !Regions.Exists(x => x.County.Id == _selectedCounty.Id && x.State.Id == _selectedState.Id)) { Regions.Add(new SAMERegion(_selectedState, _selectedCounty)); var bindingList = new BindingList<SAMERegion>(Regions); var source = new BindingSource(bindingList, null); datagridRegions.DataSource = source; comboCounty.SelectedIndex = -1; _selectedCounty = null; } }