PropertyGrid Dirty |
Post Reply |
Author | |
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
Posted: 23 March 2008 at 12:12pm |
Is there an easy way to programmatically tell any PropertyGrid items have been modified by the user (for example, a Dirty property)?
I've tried comparing the DefaultValue to the Value property, but in the case of Enums, the DefaultValue returns the translated label for the enum, while the Value property returns the actual value of the enum. The other option is to store the original value of each child item and then compare, but this is tedious when you have a long list of items. If a Dirty property could be added, that would be great. Also of use would be an OriginalValue property for each item. Thanks. |
|
Aaron
Senior Member Joined: 29 January 2008 Status: Offline Points: 2192 |
Post Options
Thanks(0)
|
Hi,
If you set: wndPropertyGrid.HighlightChangedItems = True
the changed values will be highlighted
|
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
Hi Aaron,
Thanks for replying. I have the HighlighChangedItems property set already, I'm trying to determine if anything has changed programatically to decide whether or not to restart my server application. If the user hasn't changed any settings, then I'll just leave everything running as is. I guess I was just hoping that CJ would expose whatever they are using to highlight the changed items as a property for each item so we can test for changes. |
|
Aaron
Senior Member Joined: 29 January 2008 Status: Offline Points: 2192 |
Post Options
Thanks(0)
|
Hi,
You could try this:
In the ValueChanged event:
If CStr(Item.Value) <> CStr(Item.DefaultValue) Then
Item.ValueMetrics.ForeColor = vbRed 'value changed Else Item.ValueMetrics.ForeColor = vbGreen 'value changed into default value back again End If Iterate through the items:
Dim propItem As PropertyGridItem
For Each propItem In wndPropertyGrid.Categories(1).Childs(1).Childs Select Case propItem.ValueMetrics.ForeColor Case vbRed: MsgBox "Value changed..." Case vbGreen: MsgBox "Value changed back to original..." Case Else: MsgBox "Value never changed..." End Select Next propItem Test with checkbox,string and enum, the other items you have to check yourself
|
|
Aaron
Senior Member Joined: 29 January 2008 Status: Offline Points: 2192 |
Post Options
Thanks(0)
|
Hi,
In the test I used PropertyGridItemString and not PropertyGridItemEnum, I did add some constraints to the PropertyGridItemString. In this case you are able to compare the Item.DefaultValue with the Item.Value
|
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
Hi Aaron,
Thanks for your help. I'm not sure that I can get things to work the way that I want with your code when using PropertyGridItemString because the constraints don't seem to work (nor does the drop-down appears). I have a PropertyGridItem that needs to show Yes/No in a drop-down. Using the PropertyGridItemBoolean would be ideal here, but it only seems to show True/False. So I use a PropertyGridItemEnum and set constraints for 0 = No, -1 = Yes. I've tried using constraints with PropertyGridItemString and PropertyGridItemBool, but they don't seem to do anything for those item types. You mention that you got the PropertyGrid to show constraints for the "string" type...how did you do it? (NOTE: I am now beta testing v12, so maybe it is a problem with the new version?). In any case, it seems to me that the PropertyGridItemEnum type should return its underlying value for the DefaultValue property and *not* the constraint caption, since that is purely cosmetic. What do you think? |
|
Baldur
Senior Member Joined: 22 November 2006 Location: Germany Status: Offline Points: 244 |
Post Options
Thanks(0)
|
If you use PropertyGridItemString, you have to add an inplacebutton with Id 101 for dropdownbutton.
In Changing-Event you can check against the constaints and if false set cancel to true.
|
|
Aaron
Senior Member Joined: 29 January 2008 Status: Offline Points: 2192 |
Post Options
Thanks(0)
|
Hi,
You don't have to add an inplaceButton just set Item.Flags = ItemHasComboButton.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |