如何设置为一个TreeView一些但不是所有节点的图像? [英] How do I set an image for some but not all nodes in a TreeView?

查看:148
本文介绍了如何设置为一个TreeView一些但不是所有节点的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的TreeView Windows窗体控件与的ImageList ,我想一些显示图像的节点的,但其他人没有图像。

I have a TreeView windows forms control with an ImageList, and I want some of the nodes to display images, but the others to not have images.

我的的希望有一个空格所在的形象应该是。我的没有的希望看起来像树视图将借鉴如果没有一个ImageList线的图像。我如何得到它绘制图像的一些项目,而不是别人,而不诉诸笨拙黑客这样?

I don't want a blank space where the image should be. I don't want an image that looks like the lines that the TreeView would draw if it didn't have an ImageList. How do I get it to draw images for some items and not others, without resorting to clumsy hacks like that?

推荐答案

我想这一次,我不认为这是可能的。

I tried this once and I don't think it is possible.

如果您尝试设置两个 ImageKey 的ImageIndex 来未设置值的控制只是默认值的ImageIndex 0以下code:

If you try to set both ImageKey and ImageIndex to "not set" values the control just defaults ImageIndex to 0. The following code:

treeView.ImageKey = "Value";
Debug.WriteLine(treeView.ImageIndex);
treeView.ImageKey = null;
Debug.WriteLine(treeView.ImageIndex);
treeView.ImageIndex = -1;
Debug.WriteLine(treeView.ImageIndex);

生成输出:

-1
0
0

这样的告诉你,控制开发商要确保总有一个默认的图像。这只是给你留下了黑客的选择,我很害怕。

This kind of tells you that the control developers wanted to make sure that there was always a default image. That just leaves you with the hack options I'm afraid.

这篇关于如何设置为一个TreeView一些但不是所有节点的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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