'PropertyGrid UITypeEditor Disable cell edit
I have a property grid and one of the properties uses a UITypeEditor to edit the value (on a form).
However the property is still editable, which I do not want. Is there a way to do this? I looked at this similar question Propertygrid UIEditor disabling value editing through Keyboard but it does not solve my problem as the solution is a simple dropdown list using TypeConverter.
Solution 1:[1]
I found a workaround like this (PropertyValueChanged event for PropertyGrid):
private void propertyGridNewBonus_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
switch (e.ChangedItem.Label)
{
case "somePropertyLabel":
newBonus.somePropertyValue = e.OldValue.ToString();
break;
default:
break;
}
}
just restoring old value while user edits it in propertyGrid. This looks like value is editable, but after comitting old value is restored so the only way to change it is to use custom TypeConverter, UITypeEditor or so.
Solution 2:[2]
For future use as these answer are not how it's done anymore. Set ReadOnly to true or default is false when not applied.
[Browsable(true)]
[ReadOnly(true)]
[Description("Behind the scenes identifier for a record.")]
[Category("Record Info")]
[DisplayName("Identifier")]
public string Identifier
{
get
{
return _identifier;
}
set
{
_identifier = value.Trim();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | avb |
| Solution 2 |
