/*递归方法*/ private void BindArea(string cityNo, int level, string pre) { List<AreaTInfo> cityList = new List<AreaTInfo>(); foreach (AreaTInfo item in areaList) { if (item.F_AreaSN==cityNo.Trim()) { cityList.Add(item); } } string preStr = string.Empty; if (level > 0) { preStr +=pre+ "|"; for (int i = 0; i < 2; i++) { preStr += "-"; } } int newye = level + 1; foreach (AreaTInfo item in cityList) { this.cmb_Area.Items.Add(preStr+new AreaInfo(item.AreaSN,item.AreaName).ToString()); dic.Add(item.AreaSN,preStr+new AreaInfo(item.AreaSN,item.AreaName).ToString()); BindArea(item.AreaSN, newye, preStr); } } Dictionary<string, string> dic = new Dictionary<string, string>(); string _areaSN = string.Empty; /*ComboBox SelectedIndexChanged 事件*/ private void cmb_Area_SelectedIndexChanged(object sender, EventArgs e) { string tmp = this.cmb_Area.SelectedItem.ToString(); /*遍历Dictionary<string,string>*/ foreach (KeyValuePair<string,string> item in dic) { if (item.Value==tmp) { _areaSN = item.Key; } } }递归绑定ComboBox

相关文章: