DevExpress的TreeList的常用属性设置以及常用事件
生活随笔
收集整理的這篇文章主要介紹了
DevExpress的TreeList的常用属性设置以及常用事件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
Winform控件-DevExpress18下載安裝注冊以及在VS中使用:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243
DevExpress的TreeList怎樣設置數據源,從實例入手:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102548490
在上面實現簡單的TreeList并設置數據源,顯示效果仍然不是想要的樹形結構的效果。
如果想實現如下這樣效果,還需要進行進一步的屬性設置。
?
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。
實現
?/// <summary>/// 為樹控件設置數據源/// </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, List<DataTreeNode> data, string fieldName, string keyFieldName, string parentFieldName){#region 設置節點圖標System.Windows.Forms.ImageList imgList = new System.Windows.Forms.ImageList();imgList.Images.AddRange(imgs);treeList.SelectImageList = imgList;//目錄展開treeList.AfterExpand -= treeList_AfterExpand;treeList.AfterExpand += treeList_AfterExpand;//目錄折疊treeList.AfterCollapse -= treeList_AfterCollapse;treeList.AfterCollapse += treeList_AfterCollapse;//數據節點單擊,開啟整行選中treeList.MouseClick -= treeList_MouseClick;treeList.MouseClick += treeList_MouseClick;//數據節點雙擊選中treeList.MouseDoubleClick -= treeList_MouseDoubleClick;treeList.MouseDoubleClick += treeList_MouseDoubleClick;//焦點離開事件treeList.LostFocus -= treeList_LostFocus;treeList.LostFocus += treeList_LostFocus;#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.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.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 });#endregion#region 綁定數據源treeList.KeyFieldName = keyFieldName;treeList.ParentFieldName = parentFieldName;treeList.DataSource = data;treeList.RefreshDataSource();#endregion#region 初始化圖標SetNodeImageIndex(treeList.Nodes.FirstOrDefault());#endregion}?
總結
以上是生活随笔為你收集整理的DevExpress的TreeList的常用属性设置以及常用事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DevExpress的TreeList怎
- 下一篇: C#中全局作用域的常量、字段、属性、方法