private void cboRegion_SelectedIndexChanged(object sender, EventArgs e) { CADASTRAL_REGION region = cboRegion.SelectedItem as CADASTRAL_REGION; if (region != null && !string.IsNullOrEmpty(region.CODE)) { List <MUNICIPALITY> municipalities = _basicService.LoadAllMUNICIPALITY(_businessParam).Where(c => c.ID_CADASTRAL_REGION == region.ID_CADASTRAL_REGION).OrderBy(c => c.NAME).ToList(); municipalities.Insert(0, new MUNICIPALITY { NAME = "---", CODE = "", ID_MUNICIPALITY = -1 }); cboMunicipality.DataSource = municipalities; cboMunicipality.DisplayMember = "NAME"; cboMunicipality.ValueMember = "ID_MUNICIPALITY"; CADASTRAL_ZONE cadastreZone = cboRegionZone.SelectedItem as CADASTRAL_ZONE; int prevCodeLength = cadastreZone.CODE.Length; txtCodeRegion.Text = region.CODE.Substring(prevCodeLength, region.CODE.Length - prevCodeLength); if (municipalities == null || municipalities.Count == 0) { txtCodeMunicipality.Text = ""; txtCodeTerriturialUnit.Text = ""; cboMunicipality.DataSource = null; cboTerritorialUnit.DataSource = null; } txtCodeRegion.ReadOnly = true; } else { cboMunicipality.DataSource = null; txtCodeRegion.Text = ""; txtCodeRegion.ReadOnly = false; } }