//选中节点事件 private void tvProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { NodeItem item = this.tvProperties.SelectedItem as NodeItem; string nodeText = "Name:" + item.DisplayName + "|ID:" + item.id.ToString(); label1.Content = nodeText; }
private List <NodeItem> getPeoples(peoples equkCommonData) { List <NodeItem> treeViewItemSource = new List <NodeItem>(); NodeItem peopleRootNode = new NodeItem { parentId = -1, DisplayName = "证件类型", id = 0 }; treeViewItemSource.Add(peopleRootNode); List <people> peopleTypes = equkCommonData.PeopleList; List <NodeItem> peopleDicData = new List <NodeItem>(); int nodeCount = peopleRootNode.parentId + 1; foreach (people aPeopleType in peopleTypes) { NodeItem peopleNode = new NodeItem { //parentId = peopleRootNode.id, DisplayName = aPeopleType.name, id = Int32.Parse(aPeopleType.code), }; peopleDicData.Add(peopleNode); } peopleRootNode.Children = peopleDicData; return(treeViewItemSource); }
private List <NodeItem> getIDPublishers(IDPublishers equkCommonData) { //记录节点与id对 Hashtable provAndChildren = new Hashtable(); Hashtable cityAndChildren = new Hashtable(); List <NodeItem> treeViewItemSource = new List <NodeItem>(); NodeItem idPubsRootNode = new NodeItem { parentId = -1, DisplayName = "发证机关", id = 0 }; treeViewItemSource.Add(idPubsRootNode); //创建用于存储省的List List <NodeItem> rootChildrenList = new List <NodeItem>(); idPubsRootNode.Children = rootChildrenList; List <IDPublisher> idPubs = equkCommonData.IdPublisherList; foreach (IDPublisher aIdPub in idPubs) { //增加省 NodeItem idPubProvNode = new NodeItem { DisplayName = aIdPub.pro, }; if (!provAndChildren.ContainsKey(aIdPub.pro)) { List <NodeItem> idPubsDicData = new List <NodeItem>(); provAndChildren.Add(aIdPub.pro, idPubsDicData); //将省加到root节点的children rootChildrenList.Add(idPubProvNode); } //************************************************************************* //增加市 NodeItem idPubCityNode = new NodeItem { DisplayName = aIdPub.city, }; List <NodeItem> provChildrenList = provAndChildren[aIdPub.pro] as List <NodeItem>; if (!cityAndChildren.ContainsKey(aIdPub.city)) { List <NodeItem> idPubsDicData = new List <NodeItem>(); cityAndChildren.Add(aIdPub.city, idPubsDicData); //将市节点加到省的children if (provChildrenList == null) { continue; } provChildrenList.Add(idPubCityNode); } idPubProvNode.Children = provChildrenList; //************************************************************************* //增加县、区 NodeItem idPubAreaNode = new NodeItem { DisplayName = aIdPub.area, id = Int32.Parse(aIdPub.id), }; //将区县节点加到市的children List <NodeItem> cityChildrenList = cityAndChildren[aIdPub.city] as List <NodeItem>; if (cityChildrenList == null) { continue; } cityChildrenList.Add(idPubAreaNode); idPubCityNode.Children = cityChildrenList; } return(treeViewItemSource); }