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

绑定的数据源里有个字段type,当type为“板式”,“沙发”时,树节点前面的复选框自动被选中,怎么实现... 绑定的数据源里有个字段type,当type为“板式”,“沙发”时,树节点前面的复选框自动被选中,怎么实现 展开
 我来答
weizejun198909
2013-09-27 · 超过38用户采纳过TA的回答
知道小有建树答主
回答量:96
采纳率:0%
帮助的人:71.7万
展开全部

            DataTable dtTree = new DataTable();
            dtTree.Columns.Add("ID",typeof(string));
            dtTree.Columns.Add("Code", typeof(string));
            dtTree.Columns.Add("Name", typeof(string));
            dtTree.Columns.Add("Description", typeof(string));
            dtTree.Columns.Add("ParentID", typeof(string));
            //新增加的列 布尔类型才能绑定checkbox
            dtTree.Columns.Add("Tag", typeof(bool));
            dtTree.Columns.Add("Happy", typeof(string));

            DataRow row = dtTree.NewRow();
            row["ID"] = "1";
            row["Code"] = "001";
            row["Name"] = "野原广志";
            row["Description"] = "野原广志";
            row["ParentID"] = "-1";
            row["tag"] = false;
            row["Happy"] = "爱吃青椒";
            dtTree.Rows.Add(row);

            DataRow row2 = dtTree.NewRow();
            row2["ID"] = "2";
            row2["Code"] = "002";
            row2["Name"] = "野原美呀";
            row2["Description"] = "野原美呀";
            row2["ParentID"] = "-1";
            row2["tag"] = false;
            row2["Happy"] = "爱吃青椒";
            dtTree.Rows.Add(row2);

            DataRow row3 = dtTree.NewRow();
            row3["ID"] = "3";
            row3["Code"] = "003";
            row3["Name"] = "野原新之助";
            row3["Description"] = "野原新之助";
            row3["ParentID"] = "-1";
            row3["tag"] = false;
            row3["Happy"] = "不爱吃青椒";
            dtTree.Rows.Add(row3);

            DataRow row4 = dtTree.NewRow();
            row4["ID"] = "4";
            row4["Code"] = "004";
            row4["Name"] = "野原小白";
            row4["Description"] = "野原小白";
            row4["ParentID"] = "3";
            row4["tag"] = false;
            row4["Happy"] = "不爱吃青椒";
            dtTree.Rows.Add(row4);

            //模拟数据 将查询出来的datatable添加一列 例如:tag
            //然后查询datatable type列 当type为“板式”,“沙发”时 将tag列置为true
            DataRow[] drs = dtTree.Select("Happy='爱吃青椒'");
            foreach (DataRow item in drs)
            {
                item["tag"] = true;
            }
            treeList1.DataSource = dtTree;

 

 

RXC55555
2013-09-27 · TA获得超过135个赞
知道小有建树答主
回答量:121
采纳率:0%
帮助的人:115万
展开全部

可以使用DataTrigger

<DataTrigger Binding="{Binding Path=Type}" Value="板式">
        <Setter Property="IsSelected" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Type}" Value="沙发">
        <Setter Property="IsSelected" Value="True" />
</DataTrigger>

详细参考MSDN

本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式