propertygrid browsable attribute


J

jan

after a lot of googling and trial and error, I now can change the browsable
attribute of a field in a propertygrid. But it does not update the window
directly. I tried to use good old friends Invalidate and Update, but it does
not help. Only when I select a different object and then the original again,
the change is visible. Anyone can tell me what I am missing?

This is the code:
Public Sub SetBrowsable(ByVal prop As String, ByVal val As Boolean)
Dim attributes As AttributeCollection
attributes =
TypeDescriptor.GetProperties(SelectedObject.GetType()).Item(prop).Attributes
Dim attr As BrowsableAttribute
attr = CType(attributes(GetType(BrowsableAttribute)),
BrowsableAttribute)
Dim field As FieldInfo
field = attr.GetType().GetField("Browsable", &HFFFFFFFF) ' not sure
which flag is required
If Not field Is Nothing Then
field.SetValue(attr, val, BindingFlags.NonPublic +
BindingFlags.Instance, Nothing, Nothing)
Invalidate(True)
Update()
End If
End Sub

Thanks,
Jan
 
Ad

Advertisements

J

jan

Found it: all it takes is selecting the same object again in the property
grid (grid.SelectedObject = grid.SelectedObject).

Case closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top