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; } }
private void cboTerritorialUnit_SelectedIndexChanged(object sender, EventArgs e) { try { TERRITORIAL_UNIT territorialUnit = cboTerritorialUnit.SelectedItem as TERRITORIAL_UNIT; if (territorialUnit != null && !string.IsNullOrEmpty(territorialUnit.CODE)) { MUNICIPALITY municipality = cboMunicipality.SelectedItem as MUNICIPALITY; int prevCodeLength = municipality.CODE.Length; txtCodeTerriturialUnit.Text = territorialUnit.CODE.Substring(prevCodeLength, territorialUnit.CODE.Length - prevCodeLength); txtCodeTerriturialUnit.ReadOnly = true; } else { txtCodeTerriturialUnit.Text = ""; txtCodeTerriturialUnit.ReadOnly = false; } } catch (Exception ex) { } }