c#.net中的treeview控件 [英] treeview controll in c#.net

查看:65
本文介绍了c#.net中的treeview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i需要一个树控件,在根节点处有一个
图像,在c#win表单应用程序中需要在他的子节点处复选框..

hi

i need a tree controll with
image at root node and checkbox at his child node in c# win form application..

推荐答案

一种方法是使用自定义ImageList,其中包含复选框图像(已选中和未选中)以及其他空白/自定义图像。



将TreeView上的CheckBoxes属性设置为True。定义如下课程:



One way is to use a custom ImageList which contains the 'checkbox' images (checked and unchecked) and an additional blank/custom image.

Set the CheckBoxes property on the TreeView to True. Define a class as below:

public class NonCheckableTreeNode : TreeNode
{

}





使用自定义类型添加节点后,将其StateImageIndex设置为空白图片的索引(或其他情况)。



然后处理BeforeCheck事件在TreeView上检查节点是否属于自定义类型。

虽然只有在以编程方式添加项目时才会真正起作用。



Once you have added the node using the custom type, set its StateImageIndex to the index of the blank picture (or other in your case).

Then handle the BeforeCheck event on the TreeView and check if the node is of the custom type.
Although this would only really work if you are adding the items programatically.

private void treeView1_BeforeCheck(object sender, TreeViewCancelEventArgs e)
{
    if (e.Node.GetType() == typeof(NonCheckableTreeNode))
        e.Cancel = true;
}





希望这会有所帮助。



Hope this helps.


这篇关于c#.net中的treeview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆