private void XtraUserControlBlankList_Load(object sender, EventArgs e) { this.BlankTreeList.Columns.Clear(); TreeListColumn tc1 = new TreeListColumn(); tc1.Name = "treeListColumn1"; tc1.FieldName = "BlankID"; tc1.Caption = "主键ID"; tc1.VisibleIndex = 0;//此为必须设置的属性,否则无法显示列 TreeListColumn tc2 = new TreeListColumn(); tc2.FieldName = "BlankName"; tc2.Caption = "行名"; tc2.VisibleIndex = 1; TreeListColumn tc3 = new TreeListColumn(); tc3.Caption = "父级ID"; tc3.FieldName = "ParentId"; tc3.VisibleIndex = 2; this.BlankTreeList.Columns.AddRange(new TreeListColumn[] { tc1, tc2, tc3}); //清空现有节点 this.BlankTreeList.Nodes.Clear(); BlankTreeList.AppendNode(new object[] { "Allblanklist","全部"}, null); //根据节点的字段ID名称查找定位节点 TreeListNode node = this.BlankTreeList.FindNodeByFieldValue("BlankID", "Allblanklist"); //在filedName列中查找所属值得的节点 DataTable dt = blankBll.GetBlankList(); DataView dv = new DataView(dt); dv.RowFilter = "ParentId = '-1'"; if (dt.Rows.Count > 0) { foreach (DataRowView dv1 in dv) { object[] nodeview = { dv1["BlankID"], dv1["BlankName"], dv1["ParentId"] }; TreeListNode tn = BlankTreeList.AppendNode(nodeview, node); GetChild(dv1["BlankID"].ToString(),dt,tn);//参数(父级ID,DataTable表,父节点) } } node.ExpandAll(); }
private void GetChild(string upnode, DataTable dt,TreeListNode tn) { try { DataView dv = new DataView(dt); dv.RowFilter = "ParentId = '" + upnode + "'"; foreach (DataRowView dv1 in dv) { object[] nodeview = { dv1["BlankID"], dv1["BlankName"], dv1["ParentId"] }; TreeListNode childnode = BlankTreeList.AppendNode( nodeview , tn); GetChild(dv1["BlankID"].ToString(), dt, childnode);//参数(父级ID,DataTable表,父节点) } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BlankTreeList_FocusedNodeChanged_1(object sender, FocusedNodeChangedEventArgs e) { TreeListNode curNode = e.Node; if (curNode == null) return; TxtE1.Text = curNode.GetValue("BlankID").ToString(); }