开发者

Propertygrid UIEditor disabling value editing through Keyboard

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.

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 displayed across Country, but I can directly edit Algeria to any other value, defea开发者_JS百科ting the purpose of a List to choose from.


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.

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
   {
      ...
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜