码迷,mamicode.com
首页 > 其他好文 > 详细

TreeList

时间:2020-12-18 12:27:35      阅读:2      评论:0      收藏:0      [点我收藏+]

标签:children   svi   field   author   public   treelist   lis   asc   ado   

public class TreeListUtil
{
private static Image[] imgs = null;
private static int pos = 0;
/// 为树控件设置数据源
/// </summary>
/// <param name="treeList">树控件</param>
/// <param name="data">数据对象</param>
/// <param name="fieldName">显示的字段</param>
/// <param name="keyFieldName">键字段</param>
/// <param name="parentFieldName">父级键字段</param>
public static void SetTreeListDataSource(DevExpress.XtraTreeList.TreeList treeList,TreeListColumn colNode, List<T_Bd_Authority> data, string fieldName, string keyFieldName, string parentFieldName,List<Image> lstImg)
{
#region 设置节点图标

System.Windows.Forms.ImageList imgList = new System.Windows.Forms.ImageList();
imgs = lstImg.ToArray();
imgList.Images.AddRange(imgs);

treeList.SelectImageList = imgList;
#endregion

#region 设置列头、节点指示器面板、表格线样式

treeList.OptionsView.ShowColumns = false; //隐藏列标头
treeList.OptionsView.ShowIndicator = false; //隐藏节点指示器面板

treeList.OptionsView.ShowHorzLines = false; //隐藏水平表格线
treeList.OptionsView.ShowVertLines = false; //隐藏垂直表格线
treeList.OptionsView.ShowIndentAsRowStyle = false;

#endregion

#region 初始禁用单元格选中,禁用整行选中

treeList.OptionsView.ShowFocusedFrame = true; //设置显示焦点框
treeList.OptionsSelection.EnableAppearanceFocusedCell = false; //禁用单元格选中
treeList.OptionsSelection.EnableAppearanceFocusedRow = false; //禁用正行选中
//treeList.Appearance.FocusedRow.BackColor = System.Drawing.Color.Red; //设置焦点行背景色

#endregion

#region 设置TreeList的展开折叠按钮样式和树线样式

//treeList.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
//treeList.LookAndFeel.UseDefaultLookAndFeel = false;

treeList.OptionsView.ShowButtons = true; //显示展开折叠按钮
treeList.LookAndFeel.UseDefaultLookAndFeel = false; //禁用默认外观与感觉
treeList.LookAndFeel.UseWindowsXPTheme = true; //使用WindowsXP主题
treeList.TreeLineStyle = DevExpress.XtraTreeList.LineStyle.Percent50; //设置树线的样式

#endregion

#region 添加单列

//DevExpress.XtraTreeList.Columns.TreeListColumn colNode = new DevExpress.XtraTreeList.Columns.TreeListColumn();
colNode.Name = String.Format("col{0}", fieldName);
colNode.Caption = fieldName;
colNode.FieldName = fieldName;
colNode.VisibleIndex = 0;
colNode.Visible = true;
colNode.AppearanceCell.Font = new System.Drawing.Font("微软雅黑", 9F);

colNode.OptionsColumn.AllowEdit = false; //是否允许编辑
colNode.OptionsColumn.AllowMove = false; //是否允许移动
colNode.OptionsColumn.AllowMoveToCustomizationForm = false; //是否允许移动至自定义窗体
colNode.OptionsColumn.AllowSort = false; //是否允许排序
colNode.OptionsColumn.FixedWidth = false; //是否固定列宽
colNode.OptionsColumn.ReadOnly = true; //是否只读
colNode.OptionsColumn.ShowInCustomizationForm = true; //移除列后是否允许在自定义窗体中显示

treeList.Columns.Clear();
treeList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { colNode });
//如果有子节点,那么需要根据节点是否展开的状态赋值不同的图片;从而实现节点的展开和关闭是不同图片的功能
treeList.CustomDrawNodeImages += TreeList_CustomDrawNodeImages;
#endregion

#region 绑定数据源

treeList.KeyFieldName = keyFieldName;
treeList.ParentFieldName = parentFieldName;
treeList.DataSource = data;
treeList.RefreshDataSource();

#endregion

#region 初始化图标

//SetNodeImageIndex(treeList.Nodes.FirstOrDefault());

#endregion
}

private static void TreeList_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e)
{
if (imgs != null && imgs.Length - 1 >= e.Node.Id)
{
e.SelectImageIndex = e.Node.Id;
}

//T_Bd_Authority nodeData = (T_Bd_Authority)e;
//if (e.Node.HasChildren)
// if (e.Node.Expanded)
// e.SelectImageIndex = 1;
// else
// e.SelectImageIndex = 0;
//else
// e.SelectImageIndex = 2;
}
}

TreeList

标签:children   svi   field   author   public   treelist   lis   asc   ado   

原文地址:https://www.cnblogs.com/dengronghua/p/14127945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!