xtraTreeList某个节点的指定列怎么添加控件?
本帖最后由 mypboss 于 2014-10-20 10:18 编辑跪求大神解答,如下图功能
写了段简单的代码,可控件这么加上后点击应该是赋值没有成功导致program.cs报未将对象应用到实例,贴上代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace mytest_gis
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
//InitProjectsData();
buildTree();
}
public void buildTree()
{
DevExpress.XtraTreeList.Nodes.TreeListNode rootNode = this.treeList1.AppendNode(new object[] { "张领导", 001 }, null);
rootNode.SetValue(this.treeListColumn1, "张领导");
rootNode.SetValue(this.treeListColumn2, "001");
DevExpress.XtraTreeList.Nodes.TreeListNode node1, node2;
node1 = rootNode.Nodes.Add(new object[] { "王秘书", 001 });
node1.SetValue(this.treeListColumn1, "王秘书");
node1.SetValue(this.treeListColumn2, "0001");
node2 = node1.Nodes.Add(new object[] { "赵司机", 00001 });
node2.SetValue(this.treeListColumn1, "赵司机");
node2.SetValue(this.treeListColumn2, "00001");
}
private void InitProjectsData()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Table_AX");//创建dataTable
dt.Columns.Add("ID", System.Type.GetType("System.String"));//创建列方式一
dt.Columns.Add("PID", System.Type.GetType("System.String"));
dt.Columns.Add("NAME", System.Type.GetType("System.String"));
DataColumn dc = new DataColumn("FLAG", System.Type.GetType("System.Boolean"));//创建列方式二
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["ID"] = "0";
dr["PID"] = "null";
dr["NAME"] = "aaa";
dr["FLAG"] = true;
dt.Rows.Add(dr);
DataRow dr2 = dt.NewRow();
dr2["ID"] = "1";
dr2["PID"] = "0";
dr2["NAME"] = "bbb";
dr2["FLAG"] = true;
dt.Rows.Add(dr2);
DataRow dr3 = dt.NewRow();
dr3["ID"] = "2";
dr3["PID"] = "1";
dr3["NAME"] = "ccc";
dr3["FLAG"] = true;
dt.Rows.Add(dr3);
ds.Tables.Add(dt);
this.repositoryItemTreeListLookUpEdit1.TreeList.KeyFieldName = "ID";
this.repositoryItemTreeListLookUpEdit1.TreeList.ParentFieldName = "PID";
this.repositoryItemTreeListLookUpEdit1.DisplayMember = "NAME";
this.repositoryItemTreeListLookUpEdit1.ValueMember = "ID";
this.repositoryItemTreeListLookUpEdit1.DataSource = ds.Tables.DefaultView;
}
private void treeList1_CustomNodeCellEdit(object sender, DevExpress.XtraTreeList.GetCustomNodeCellEditEventArgs e)
{
if (e.Node.GetValue(treeListColumn1).ToString().Equals("赵司机"))
{
switch (e.Column.FieldName)
{
case "备注":
e.RepositoryItem = repositoryItemTreeListLookUpEdit1;
InitProjectsData();
Console.WriteLine(repositoryItemTreeListLookUpEdit1.);
break;
}
}
}
}
}
设计页面见图2
页:
[1]