PropertyGrid中UIEditor禁用值通过键盘编辑键盘、编辑、PropertyGrid、UIEditor

2023-09-06 05:50:55 作者:煙花消散ぐ記憶殘〃

我有一个使用UITypeEditor的显示一个列表框,选择一个item.THis项的​​PropertyGrid中得到上选择..但在proertygrid我怎么直接禁用所选项目的编辑,从readonly选项prevents它返回得到编辑。

I have a propertygrid that uses UITypeEditor to display a Listbox and select a item.THis item gets returned on the proertygrid on selection ..But how do I disable editing of the selected item directly,readonly option prevents it from getting edited.

比方说,我是从另一种形式,它在我选择阿尔及利亚和preSS确定,阿尔及利亚的跨国家持续显示一个listbox..When显示国家名单更改属性的国家,但我可以直接编辑阿尔及利亚为任何其他值,击败一个列表的目的选择...任何帮助将非常AP preciated ... thanks..Vis_Dav

Let's say I'm changing a Property Country from another form which displays a list of countries in a listbox..When I select 'Algeria' and press OK,'Algeria' is displyed across Country,but I can directly edit Algeria to any other value,defeating the purpose of a List to choose from...Any help will be much appreciated...thanks..Vis_Dav

推荐答案

如果你只是想显示值的下拉列表来选择,而是prevent从输入任何内容中的属性值的用户PropertyGrid控件,您可以从类型转换器派生并重写 GetStandardValues​​Exclusive 的方法简单地返回true。

If you just want to show a drop-down list of values to select from, but prevent the user from typing anything into the property value within the PropertyGrid control, you can derive from TypeConverter and override the GetStandardValuesExclusive method to simply return true.

要提供一组允许值的下拉菜单,你需要重写的 GetStandardValues​​Supported 方法返回true,那么覆盖 GetStandardValues​​ 返回要在下拉列表中,显示允许值的列表。

To provide the set of allowable values to show in the drop-down you need to override the GetStandardValuesSupported method to return true then override GetStandardValues to return the list of allowable values you want to show in the drop-down list.

一旦你有在地方,你只需要像这样的属性来指定您的自定义类型转换器:

Once you have that in place, you just need to specify your custom type converter on the property like so:

public class MyTypeConverter : TypeConverter
{
  //Override GetStandardValuesExclusive, 
  //GetStandardValues and GetStandardValuesSupported
}

public class SomeClass
{

   [TypeConverter(typeof(MyTypeConverter))]
   public string SomePropertry
   {
      ...
   }
}