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 + "|"; }