using DevExpress.Utils.Design; namespace Yw.WinFrmUI { public partial class SimpleTreeViewCtrl : DevExpress.XtraEditors.XtraUserControl { /// /// /// public SimpleTreeViewCtrl() { InitializeComponent(); this.treeList1.InitialDefaultSettings(); this.layoutControl1.SetupLayoutControl(); } /// /// 聚焦改变事件 /// public event Action FocusedChangedEvent; /// /// 所有绑定列表 /// private List _allBindingList = null; /// /// 绑定数据 /// public void SetBindingData(List allList) { _allBindingList = new List(); allList?.ForEach(x => { _allBindingList.Add(x); }); this.treeList1.DataSource = _allBindingList; this.treeList1.ForceInitialize(); } /// /// 全部展开 /// public void ExpandAll() { this.treeList1.ExpandAll(); } /// /// 全部折叠 /// public void CollapseAll() { this.treeList1.CollapseAll(); } /// /// 显示树线 /// public bool ShowTreeLines { get { return this.barCkTreeLine.Checked; } set { this.barCkTreeLine.Checked = value; } } /// /// 显示搜索框 /// public void ShowSearchControl() { this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; } /// /// 关闭搜索框 /// public void CloseSearchControl() { this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; } /// /// 选择图片列表 /// [DefaultValue(null)] [TypeConverter(typeof(ImageCollectionImagesConverter))] public object SelectImageList { get { return this.treeList1.SelectImageList; } set { this.treeList1.SelectImageList = value; } } /// /// 工具条可见性 /// public bool ToolBarVisible { get { return this.bar1.Visible; } set { this.bar1.Visible = value; } } //全部展开 private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.treeList1.ExpandAll(); } //全部折叠 private void barBtnCollpseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.treeList1.CollapseAll(); } //检索(menu) private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.layoutControlItem1.Visibility == DevExpress.XtraLayout.Utils.LayoutVisibility.Always) this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; else this.layoutControlItem1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; } //树线 private void barCkTreeLine_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.treeList1.OptionsView.ShowTreeLines = this.barCkTreeLine.Checked ? DefaultBoolean.True : DefaultBoolean.False; } //聚焦节点改变 private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { var vm = this.treeList1.GetDataRecordByNode(e.Node) as SimpleTreeViewModel; this.FocusedChangedEvent?.Invoke(vm); } } }