devexpress treelist 绑定数据时让部分节点默认选择
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;
可以使用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