Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
In older versions of VB you could call PropertyChanged(PropertyName as String) to update the designer when internal values changed. Could someone please fill me in on the .NET equivilant of PropertyChanged or a way of updating property values in the designer when they are changed internally on a usercontrol?
Posted

Maybe not, because that's not working for me.

 

Lets say you build a usercontrol with 2 public properties, MyProp1 and MyProp2, and the properties' values are stored privately as m_MyProp1 and m_MyProp2.

 

Changing the value of MyProp1 affects the value stored for MyProp2, therefor MyProp2 needs to be updated in the designer.

 

In VB6 you would simply put

 

PropertyChanged "MyProp2"

 

in the Set block of MyProp1. This would trigger the Get block for MyProp2 and update its value in the designer's property grid so the programmer using the control at design time would automatically see MyProp2's new value without having to actually click on the property.

 

It would look something like this in VB6:

 


Public Property Get MyProp1() as String
   Return m_MyProp1
End Property

Public Property Let MyProp1(vNewValue as String)
   m_MyProp1 = vNewValue
   If vNewValue = "Something Important Related To MyProp2" then 
        m_MyProp2 = "Whatever"
        PropertyChanged "MyProp2"
   End If
End Property

Public Property Get MyProp2() as String
   Return m_MyProp2
End Property

 

Here is the .Net version(missing the all important PropertyChanged):

 


Public Property MyProp1() as String
    Get
        Return m_MyProp1
    End Get
    Set(Value as String)
        m_MyProp1 = value
        If value = "Something related to MyProp2" then
             m_MyProp2 = "New Value"
             ' Missing:
             ' How do I update what is displayed in the PropertyGrid
             ' for MyProp2's new value from within the control's code.
        End If
    End Set
End Property

Posted

The Answer

 

OK. Got this one figured out. Here's the answer for the next guy. It's actually just as simple(if not simpler) than VB6.

 

All you need to do is add the following attribute to the Property:

 

RefreshProperties(RefreshProperties.Repaint)

 

This will repaint all property values in the property browser.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...