[C#][DevPress]事件委托的使用
先要在代码的最前面声明一下事件、委托
delegate TreeListNode SetTreeNodeHandler(object data, TreeListNode node); event SetTreeNodeHandler AddTreeNode;
在窗体类的构造函数中绑定事件
public UserCheckItem() { InitializeComponent(); AddTreeNode = new SetTreeNodeHandler(TreeEvent); }
在窗体的Load事件中添加
private void UserCheckItem_Load(object sender, EventArgs e) { Thread th = new Thread(new ThreadStart(LoadTree1)); th.IsBackground = true; th.Start(); }
void LoadTree1() { try { DataTable dt = bll1.GetCorpCategoryList1(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i ) { if (dt.Rows[i]["Corp_Cate_Code"].ToString() == "Z") { continue; } dt.Rows[i]["Corp_Cate_Name"] = Tools.Decrypt(dt.Rows[i]["Corp_Cate_Name"].ToString()); //TreeListNode treenode = treeList1.AppendNode(new object[] { dt.Rows[i]["Corp_Cate_Name"].ToString() }, null); TreeListNode treenode = treeList1.Invoke(AddTreeNode, new object[] { dt.Rows[i]["Corp_Cate_Name"] }, null) as TreeListNode; treenode.Tag = dt.Rows[i]["Corp_Cate_Code"].ToString(); treenode.Expanded = false; CreateChildNodes(treenode); } } } catch (Exception ex) { XtraMessageBox.Show("加载列表失败:" ex.Message, "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void CreateChildNodes(TreeListNode treenode) { DataTable dt = bll2.GetCheckTableList1(treenode.Tag.ToString(), SysEnum.TableIsPublic.N); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i ) { dt.Rows[i]["Check_Tab_Name"] = Tools.Decrypt(dt.Rows[i]["Check_Tab_Name"].ToString()); //TreeListNode tempNode = treeList1.AppendNode(new object[] { dt.Rows[i]["Check_Tab_Name"].ToString() }, treenode); TreeListNode tempNode = treeList1.Invoke(AddTreeNode, new object[] { dt.Rows[i]["Check_Tab_Name"] }, treenode) as TreeListNode; tempNode.Tag = dt.Rows[i]["Check_Tab_Code"].ToString(); CreateChildNodes1(tempNode); } } }
private void CreateChildNodes1(TreeListNode treenode) { DataTable dt = bll3.GetCheckItemsList1(treenode.Tag.ToString(), SysEnum.TableIsPublic.A); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i ) { dt.Rows[i]["Check_Item_Name"] = Tools.Decrypt(dt.Rows[i]["Check_Item_Name"].ToString()); //TreeListNode tempNode = treeList1.AppendNode(new object[] { dt.Rows[i]["Check_Item_Name"].ToString() }, treenode); TreeListNode tempNode = treeList1.Invoke(AddTreeNode, new object[] { dt.Rows[i]["Check_Item_Name"] }, treenode) as TreeListNode; tempNode.Tag = dt.Rows[i]["Check_Item_Code"].ToString() ";" Convert.ToInt32(dt.Rows[i]["Check_Item_IsPublic"]) treenode.Tag.ToString(); //dt.Rows[i]["Check_Item_Code"].ToString(); CreateChildNodes2(tempNode); } } }
private void CreateChildNodes2(TreeListNode treenode) { object[] tt = treenode.Tag.ToString().Split(';'); DataTable dt = bll4.GetCheckContentList1(tt[0].ToString(), tt[1]); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i ) { dt.Rows[i]["Check_Content_Name"] = Tools.Decrypt(dt.Rows[i]["Check_Content_Name"].ToString()); //TreeListNode tempNode = treeList1.AppendNode(new object[] { dt.Rows[i]["Check_Content_Name"].ToString() }, treenode); TreeListNode tempNode = treeList1.Invoke(AddTreeNode, new object[] { dt.Rows[i]["Check_Content_Name"] }, treenode) as TreeListNode; tempNode.Tag = dt.Rows[i]; } } }
private TreeListNode TreeEvent(object data, TreeListNode node) { return this.treeList1.AppendNode(data, node); }
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { if (e.Node.Level == 3) { labelControl3.Text = e.Node.ParentNode.ParentNode.GetValue(0).ToString() "-->" e.Node.ParentNode.GetValue(0).ToString(); DataRow obj = e.Node.Tag as DataRow; labelControl4.Text = obj["Check_Content_Name"].ToString(); memoEdit1.Text = Tools.Decrypt(obj["Check_Content_Require"].ToString()); memoEdit2.Text = Tools.Decrypt(obj["Check_Content_AccArticle_Content"].ToString()); memoEdit3.Text = Tools.Decrypt(obj["Check_Content_PunishArticle_Content"].ToString()); } }