propertygrid browsable attribute

  • Thread starter Thread starter jan
  • Start date Start date
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
 
Found it: all it takes is selecting the same object again in the property
grid (grid.SelectedObject = grid.SelectedObject).

Case closed.
 
Back
Top