如何使一个精简的PropertyGrid [英] How to make a Stripped Down PropertyGrid

查看:115
本文介绍了如何使一个精简的PropertyGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个应用程序,我在树视图中显示的数据,并在树视图元素在用户双击,就点击了节点替换为节点的可编辑​​的版本。不同的节点进行编辑的方式变化很大,因此,使用内置的改变节点的文本能力是不能接受的。我反而需要使用属性网格,并定义属性。

I'm building an app where I show data in a tree view, and when a user double-clicks on an element in the tree view, the node they clicked on is replaced with an editable version of the node. The way different nodes are edited varies greatly, so using the built-in ability to change the text of the node is not acceptable. I instead need to use a property grid and define attributes.

唯一的问题是,属性网格示出两列:一与属性的名称,和其他与它的值。我只需要显示值列(部分用户可以编辑)。有没有一些方法来去除的第一列,或使用属性网格的功能在不同的自定义类只显示一列?

The only problem is that the property grid shows two columns: One with the name of the property, and the other with its value. I need to only show the value column (the part the user can edit). Is there some way to remove the first column, or use the property grid's functionality in a different, custom class that only shows one column?

推荐答案

这是不可能的,没有其它属性网格。这里是一个code,可以改变标签栏的宽度:

This is not possible without hacking the property grid. Here is a code that can change the label column's width:

public static void SetLabelColumnWidth(PropertyGrid grid, int width)
{
    if (grid == null)
        throw new ArgumentNullException("grid");

    // get the grid view
    Control view = (Control)grid.GetType().GetField("gridView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(grid);

    // set label width
    FieldInfo fi = view.GetType().GetField("labelWidth", BindingFlags.Instance | BindingFlags.NonPublic);
    fi.SetValue(view, width);

    // refresh
    view.Invalidate();
}

public static void ResetLabelColumnWidth(PropertyGrid grid)
{
    SetLabelColumnWidth(grid, -1);
}

使用它,就像这样,除去标签栏:

Use it just like this to remove the label column:

    SetLabelColumnWidth(propertyGrid1, 0);

复位功能恢复的标签列。

The reset function restores the label column.

当然,这是一个黑客,因此可能不会在今后的工作。也有问题:

Of course, it's a hack so it may not work in the future. There are also issues:

  • V形分路器的光标显示当鼠标移动到网格的左侧,用户可以选择它,并重新设置标签栏,如果他点击。
  • 在一些电网操作也可能恢复标签列(就像使用属性网格工具栏)。

希望这有助于!

这篇关于如何使一个精简的PropertyGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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