devexpress treelist 绑定数据时让部分节点默认选择

devexpress treelist 绑定数据时让部分节点默认选择,第1张

DataTable dtTree = new DataTable();

            dtTreeColumnsAdd("ID",typeof(string));

            dtTreeColumnsAdd("Code", typeof(string));

            dtTreeColumnsAdd("Name", typeof(string));

            dtTreeColumnsAdd("Description", typeof(string));

            dtTreeColumnsAdd("ParentID", typeof(string));

            //新增加的列 布尔类型才能绑定checkbox

            dtTreeColumnsAdd("Tag", typeof(bool));

            dtTreeColumnsAdd("Happy", typeof(string));

DataRow row = dtTreeNewRow();

            row["ID"] = "1";

            row["Code"] = "001";

            row["Name"] = "野原广志";

            row["Description"] = "野原广志";

            row["ParentID"] = "-1";

            row["tag"] = false;

            row["Happy"] = "爱吃青椒";

            dtTreeRowsAdd(row);

DataRow row2 = dtTreeNewRow();

            row2["ID"] = "2";

            row2["Code"] = "002";

            row2["Name"] = "野原美呀";

            row2["Description"] = "野原美呀";

            row2["ParentID"] = "-1";

            row2["tag"] = false;

            row2["Happy"] = "爱吃青椒";

            dtTreeRowsAdd(row2);

DataRow row3 = dtTreeNewRow();

            row3["ID"] = "3";

            row3["Code"] = "003";

            row3["Name"] = "野原新之助";

            row3["Description"] = "野原新之助";

            row3["ParentID"] = "-1";

            row3["tag"] = false;

            row3["Happy"] = "不爱吃青椒";

            dtTreeRowsAdd(row3);

DataRow row4 = dtTreeNewRow();

            row4["ID"] = "4";

            row4["Code"] = "004";

            row4["Name"] = "野原小白";

            row4["Description"] = "野原小白";

            row4["ParentID"] = "3";

            row4["tag"] = false;

            row4["Happy"] = "不爱吃青椒";

            dtTreeRowsAdd(row4);

//模拟数据 将查询出来的datatable添加一列 例如:tag

            //然后查询datatable type列 当type为“板式”,“沙发”时 将tag列置为true

            DataRow[] drs = dtTreeSelect("Happy='爱吃青椒'");

            foreach (DataRow item in drs)

            {

                item["tag"] = true;

            }

            treeList1DataSource = dtTree;

先给TreeView加个右键菜单,菜单名称addToolStripMenuItem

private void addToolStripMenuItem_Click(object sender, EventArgs e)

{

if (thistreeView1SelectedNode != null) {

TreeNode node = new TreeNode("新节点" + DateTimeNow);

thistreeView1SelectedNodeNodesAdd(node);

}

}

你这样做的话,可以加个判断就行了 答案补充 这样可以!传个值到地址拦上去,再去取就可以达到你的效果! 答案补充 选中时,取个值把这个值传到地址上面去,GET传值再去取

这样随你怎么刷新,都不会变依然是你选中的那个节点

treeListAppendNode(参数1,参数2)//添加节点的方法 例如: TreeListNode ParentNode=treeListAppendNode(null,null);//添加第一节点 ParentNodeSetValue(treeListColumns[0], "显示的值");//添加第一节点显示的值

你要的功能不是多行显示而是多列显示吧,cxDBTreeList主要有以下三个关键属性

KeyFields: 子节点ID

DisplayFields:节点内容这里就是显示内容,记得可以在界面上直接新增的,应该是双击cxDBTreeList吧

ParentFields:父节点ID

以上就是关于devexpress treelist 绑定数据时让部分节点默认选择全部的内容,包括:devexpress treelist 绑定数据时让部分节点默认选择、谁能写一个treelist右击增加子节点的C#代码。。。。急、c#中,treelist这个控件刷新后 如何不改变它之前的选中节点等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9285830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存