DevExpress TreeList树形表格组件使用
TreeList 组件
加载数据源
C# 全选
private void LoadTree(List<dt_Device> data)
{
tlAccountItem.LookAndFeel.UseDefaultLookAndFeel = false;
tlAccountItem.LookAndFeel.UseWindowsXPTheme = true;
tlAccountItem.OptionsSelection.EnableAppearanceFocusedCell = false;
tlAccountItem.KeyFieldName = nameof(dt_Device.isid);//设置主键
tlAccountItem.ParentFieldName = nameof(dt_Device.ParentIsid);//设置父级主键
tlAccountItem.RootValue = null;//顶级树结点的值
tlAccountItem.DataSource = data;
DevTreeListView.SetImageIndex(tlAccountItem, null, 1, 0);
tlAccountItem.ExpandAll();
}
获取选择节点的行对象
C# 全选
var row = (dt_Device)tlAccountItem.GetDataRecordByNode(tlAccountItem.FocusedNode);
设置节点图标
C# 全选
/// <summary>
/// 设置TreeList显示的图标
/// </summary>
/// <param name="tl">TreeList组件</param>
/// <param name="node">当前结点,从根结构递归时此值必须=null</param>
/// <param name="nodeIndex">根结点图标(无子结点)</param>
/// <param name="parentIndex">有子结点的图标</param>
public static void SetImageIndex(TreeList tl, TreeListNode node, int nodeIndex, int parentIndex)
{
if (node == null)
{
foreach (TreeListNode N in tl.Nodes)
SetImageIndex(tl, N, nodeIndex, parentIndex);
}
else
{
if (node.HasChildren || node.ParentNode == null)
{
//node.SelectImageIndex = parentIndex;
node.StateImageIndex = parentIndex;
node.ImageIndex = parentIndex;
}
else
{
//node.SelectImageIndex = nodeIndex;
node.StateImageIndex = nodeIndex;
node.ImageIndex = nodeIndex;
}
foreach (TreeListNode N in node.Nodes)
{
SetImageIndex(tl, N, nodeIndex, parentIndex);
}
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网