TreeList控件節點複選框的顯隱
一、初始化TreeList
private TreeList InitTreeList()
{
TreeList pTreeList = new TreeList()
TreeListColumn treeListColumn1 = new TreeListColumn()
pTreeList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] {
treeListColumn1})
pTreeList.Dock = System.Windows.Forms.DockStyle.Fill
pTreeList.Location = new System.Drawing.Point(0, 0)
pTreeList.Name = "pTreeList"
pTreeList.OptionsBehavior.Editable = false
pTreeList.OptionsClipboard.AllowCopy = DevExpress.Utils.DefaultBoolean.True
pTreeList.OptionsClipboard.CopyNodeHierarchy = DevExpress.Utils.DefaultBoolean.True
pTreeList.OptionsNavigation.AutoMoveRowFocus = true
pTreeList.OptionsView.ShowCheckBoxes = true
pTreeList.OptionsView.ShowColumns = false
pTreeList.OptionsView.ShowHorzLines = false
pTreeList.OptionsView.ShowIndicator = false
pTreeList.OptionsView.ShowVertLines = false
pTreeList.Size = new System.Drawing.Size(263, 207)
pTreeList.TabIndex = 0
pTreeList.AfterCheckNode += pTreeList_AfterCheckNode
pTreeList.CustomDrawNodeCheckBox += pTreeList_CustomDrawNodeCheckBox
//
// treeListColumn1
//
treeListColumn1.Caption = "treeListColumn1"
treeListColumn1.FieldName = "Name"
treeListColumn1.MinWidth = 32
treeListColumn1.Name = "treeListColumn1"
treeListColumn1.Visible = true
treeListColumn1.VisibleIndex = 0
return pTreeList
}
二、節點的顯隱控制
private void pTreeList_CustomDrawNodeCheckBox(object sender, CustomDrawNodeCheckBoxEventArgs e)
{
HideCheckBox(n => !(n.Tag is CompareData || n.Tag is DataVersionInfo), e);
}
private void HideCheckBox(Predicate<TreeListNode> conditionHanlder, CustomDrawNodeCheckBoxEventArgs e)
{
if (conditionHanlder(e.Node))
{
e.Handled = true;
}
}