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