Propertygrid issue


G

Guest

Hi,

I have an application which has two winforms. One is the parent form which
has around 20 odd controls. And the other has a propertygrid and two buttons,
viz OK and Cancel. This form runs in the designerhost. Hence if a property is
changed the componentchanged event fires and changes are seen on the control
on my first form. Is there a way to defer this event such that on click of OK
button the changes are reflected and on click of cancel i get an option to
rollback or revert the changes.

Thanks for all the help.
Regards
Ser
 
Ad

Advertisements

B

Bryan Phillips

You need to start a designer transaction when your property grid form
loads. Then, you can either commit the transaction when the user clicks
OK or roll it back to the old values when the user clicks Cancel. This
is how Visual Studio implements undo and redo when you make changes in
the various designers.
 
G

Guest

Hi Bryan,

Thanks a lot for your reply.
I had tried using DesignerTransaction. But it seems like there is an
internal commit that fires which leaves nothing to rollback or cancel. As i
am using desigherhost, the conponentchanged event seems to fire everytime a
property is changed. Is there a possiblility that this could lead to an
internal commit? If it is, then is there a way to defer componentchanged
event that fires on the propertychange?

Thanks again,
Ser
 
G

Guest

Hi Bryan,
Following is a part of the call stack. Before executing the code in the
overriden method of Component Changed event:
System.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(object
component = {label1 [System.Windows.Forms.Label], Text: label1}, object value
= Yes) + 0x196 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.SetPropertyValueCore(object
obj = {label1 [System.Windows.Forms.Label], Text: label1}, object value, bool
doUndo) + 0xd4 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.SetPropertyValue(object
obj = {label1 [System.Windows.Forms.Label], Text: label1}, object objVal =
Yes, bool reset, string undoText) + 0x3b8 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.PropertyValue.set(object value) + 0x1e bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.CommitValue(System.Windows.Forms.PropertyGridInternal.GridEntry
ipeCur =
{System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry
RightToLeft}, object value = Yes) + 0xc7 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.CommitValue(object value) + 0x4e bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.DoubleClickRow(int row, bool toggleExpand, int type) + 0x144 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.OnGridEntryLabelDoubleClick(object s, System.EventArgs e) + 0x4f bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.RaiseEvent(object key, System.EventArgs e) + 0x40 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.OnLabelDoubleClick(System.EventArgs e) + 0x27 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.OnMouseClick(int
x, int y, int count, System.Windows.Forms.MouseButtons button) + 0x105 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.OnMouseClick(int
x, int y, int count, System.Windows.Forms.MouseButtons button) + 0xe4 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.OnMouseDown(System.Windows.Forms.MouseEventArgs me) + 0x198 bytes

-------------------------------------------------------------------------------
 
Ad

Advertisements

B

Bryan Phillips

I think I mislead you about what I was thinking about. I meant to use
the UndoContext object on the DTE class. I have only used this in
macros, add-ins, and VSIP packages, but I don't see why it would not
work in a designer too.

To use the UndoContext class, call the Open method to start the
"transaction". Call the SetAborted method to revert to the state before
Open was called. Call the Close method to "commit" the final changes.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com



Hi Bryan,
Following is a part of the call stack. Before executing the code in the
overriden method of Component Changed event:
System.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(object
component = {label1 [System.Windows.Forms.Label], Text: label1}, object value
= Yes) + 0x196 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.SetPropertyValueCore(object
obj = {label1 [System.Windows.Forms.Label], Text: label1}, object value, bool
doUndo) + 0xd4 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.SetPropertyValue(object
obj = {label1 [System.Windows.Forms.Label], Text: label1}, object objVal =
Yes, bool reset, string undoText) + 0x3b8 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.PropertyValue.set(object value) + 0x1e bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.CommitValue(System.Windows.Forms.PropertyGridInternal.GridEntry
ipeCur =
{System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry
RightToLeft}, object value = Yes) + 0xc7 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.CommitValue(object value) + 0x4e bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.DoubleClickRow(int row, bool toggleExpand, int type) + 0x144 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.OnGridEntryLabelDoubleClick(object s, System.EventArgs e) + 0x4f bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.RaiseEvent(object key, System.EventArgs e) + 0x40 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.OnLabelDoubleClick(System.EventArgs e) + 0x27 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.OnMouseClick(int
x, int y, int count, System.Windows.Forms.MouseButtons button) + 0x105 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.OnMouseClick(int
x, int y, int count, System.Windows.Forms.MouseButtons button) + 0xe4 bytes

System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.OnMouseDown(System.Windows.Forms.MouseEventArgs me) + 0x198 bytes

-------------------------------------------------------------------------------

ser said:
Hi Bryan,

Thanks a lot for your reply.
I had tried using DesignerTransaction. But it seems like there is an
internal commit that fires which leaves nothing to rollback or cancel. As i
am using desigherhost, the conponentchanged event seems to fire everytime a
property is changed. Is there a possiblility that this could lead to an
internal commit? If it is, then is there a way to defer componentchanged
event that fires on the propertychange?

Thanks again,
Ser
 

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