Print Page | Close Window

PropertyGrid Dirty

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=9947
Printed Date: 28 April 2025 at 2:39am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: PropertyGrid Dirty
Posted By: jpbro
Subject: PropertyGrid Dirty
Date 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.



Replies:
Posted By: Aaron
Date Posted: 23 March 2008 at 4:44pm
Hi,
 
If you set:  wndPropertyGrid.HighlightChangedItems = True
the changed values will be highlighted


Posted By: jpbro
Date Posted: 23 March 2008 at 5:08pm
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.


Posted By: Aaron
Date Posted: 24 March 2008 at 1:38am
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


Posted By: Aaron
Date Posted: 24 March 2008 at 4:08am
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  


Posted By: jpbro
Date Posted: 25 March 2008 at 9:48am
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?





Posted By: Baldur
Date Posted: 27 March 2008 at 12:03pm
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.


Posted By: Aaron
Date Posted: 27 March 2008 at 3:15pm
Hi,
 
You don't have to add an inplaceButton just set Item.Flags = ItemHasComboButton.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net