Dynamic IsReadOnly flag...

Grids for WPF Forum

Posted 9 years ago by SledgeHammer01
Version: 10.1.0521
Avatar
Hi, I saw another thread where you were talking about dynamically changing the IsReadOnly property, but it doesn't seem to work...

I have a class as below:

public class PropertyDescriptorDataAccessorEx : PropertyDescriptorDataAccessor
{
public new bool IsReadOnly
{
get
{
return base.IsReadOnly | b;
}

set
{
b = value;
this.Refresh();
base.OnPropertyChanged("IsReadOnly");
base.OnPropertyChanged("IsReadOnlyInternal");
}
}

protected override bool IsReadOnlyInternal
{
get
{
return base.IsReadOnlyInternal | b;
}
}

}

I insert items dynamically and save the PropertyDescriptorDataAccessorEx refs for two items.

When I get a change notificaition on another item, I call the IsReadOnly = false on the saved refs.

It doesn't redraw the item as read only. Am I missing a step?

Comments (2)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

I'm assuming you are referring to this thread: http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=3957

In that thread, the CustomDataPropertyAccessor implements IPropertyDataAccessor directly, and doesn't derive from PropertyDescriptorDataAccessor. In your code, you define IsReadOnly using the "new" keyword. By adding the "new" keyword, your class will compile but your IsReadOnly property will not always be called. Adding "new" is not the same as overridding. I'd recommend reading the following article: http://msdn.microsoft.com/en-us/library/6fawty39(VS.80).aspx

You would need to override IsReadOnly, and you don't need to override IsReadOnlyInternal. So, something like:

public override bool IsReadOnly {
get {
return this.IsReadOnlyReal;
}
}

private bool isReadOnlyReal = false;
public bool IsReadOnlyReal {
get {
return this.isReadOnlyReal;
}
set {
if (this.isReadOnlyReal != value) {
this.isReadOnlyReal = value;
this.OnPropertyChanged("IsReadOnly");
}
}
}


Actipro Software Support

Posted 9 years ago by SledgeHammer01
Avatar
Oops.. wasn't paying attention to the code :).
The latest build of this product (v2019.1 build 0681) was released 18 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.