Windows窗体/ TreeView:如何仅将CheckBoxes放在树叶上?

时间:2011-11-16 05:39:08

标签: c# winforms treeview

在树视图中选择CheckBoxes = true会在每个节点上放置复选框。我只想要它们在树叶上?怎么样?

2 个答案:

答案 0 :(得分:2)

我认为您需要为节点实现ownerdraw事件处理程序,如下所示:

treeView.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
treeView.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView_DrawNode);

private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
    if(NodeWithCheckBox(e.Node))
    {
       // draw entry with checkbox
       e.DrawDefault = false;
    }
    else
    {
       e.DrawDefault = true;
    }
}

答案 1 :(得分:2)