C# winfrom 递归(城市名)
递归的定以:递归在运行过程中,自己调用自己的过程;
List<ChinaStates> list = new ChinaData().SelectAll();//查询所有中国的城市的方法; foreach (ChinaStates cs in list) { if (cs.ParentAreaCode == code) { TreeNode tn = new TreeNode(cs.AreaName); dataBind(cs.AreaCode, tn.Nodes); tnc.Add(tn); } }
把点击的城市,show出来:
string tname = ""; getData(treeView1.SelectedNode); MessageBox.Show(tname.Substring(0, tname.Length - 1)); public void getData(TreeNode tn) { if (tn.Parent != null) { getData(tn.Parent); } tname += tn.Text + "|"; }