PC Review


Reply
Thread Tools Rate Thread

Command Pattern implementation with bound winforms controls?

 
 
Samuel R. Neff
Guest
Posts: n/a
 
      22nd Mar 2005

We're working on implementing a Command Pattern design with our
application in order to help facilitate undo/redo. This is fine four
user actions we control which basically means menu actions.

However, it's not quite so clear for bound controls. We don't
directly interact with the change--the user makes a change in a
control, such as a grid, and the dataset stores the update. We
haven't interjected any code which we can funnel through a Command
object.

One work-around we're thinking is to react to the change events and
put a Command object in the stack wich some flag to indicate that the
action has already been accomplished (and thus the Execute method only
should be called for the Redo operation and not for the originating
operation).

How have others addressed this situation? Are there any examples
available of using Command pattern in a bound-control environment?

Thanks,

Sam

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
Reply With Quote
 
 
 
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      23rd Mar 2005
Hi

I think it is not a trivial job.
Here is a link for your reference.
http://www.thecodeproject.com/vb/net...f=100&forumid=
14573&select=817584#xx817584xx

Also I think you may try to post the databinding issue in the newsgroup
below.
Thanks!
microsoft.public.dotnet.framework.windowsforms.databinding

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      23rd Mar 2005
I recently created an architecture that did this.

The undo-redo architecture was interface based with the specific
implementations for the various objects conforming to the contract of the
interface but imlementing differently depending upon object type. The
interface included a do, undo and redo method. This separated the do from
the redo and enables you to create a null do with an operative redo.

For objects such as textboxes, a change notification occurred via the
standard events which created and stacked the command object as per normal,
the system called the null do command because the assumption was that
databinding would already have effected the change and subsequent undo /
redo actions were implemented using specialised code that had knowledge of
the bound control type being undone.

I can't post code as it was for a commercial client but the process was
pretty standard Command Pattern.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Samuel R. Neff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> We're working on implementing a Command Pattern design with our
> application in order to help facilitate undo/redo. This is fine four
> user actions we control which basically means menu actions.
>
> However, it's not quite so clear for bound controls. We don't
> directly interact with the change--the user makes a change in a
> control, such as a grid, and the dataset stores the update. We
> haven't interjected any code which we can funnel through a Command
> object.
>
> One work-around we're thinking is to react to the change events and
> put a Command object in the stack wich some flag to indicate that the
> action has already been accomplished (and thus the Execute method only
> should be called for the Redo operation and not for the originating
> operation).
>
> How have others addressed this situation? Are there any examples
> available of using Command pattern in a bound-control environment?
>
> Thanks,
>
> Sam
>
> B-Line is now hiring one Washington D.C. area VB.NET
> developer for WinForms + WebServices position.
> Seaking mid to senior level developer. For
> information or to apply e-mail resume to
> sam_blinex_com.



 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      23rd Mar 2005

Thanks Bob, that looks like a good solution.

Peter's post brought up an issue I hadn't considered which is when
responding to events and putting commands with empty Do methods on the
undo stack, how do you differentiate from user initiated events and
code initiated events? Seems like that still is an issue with your
proposal.

Thanks,

Sam


On Wed, 23 Mar 2005 13:50:14 +0100, "Bob Powell [MVP]"
<bob@_spamkiller_bobpowell.net> wrote:

>I recently created an architecture that did this.
>
>The undo-redo architecture was interface based with the specific
>implementations for the various objects conforming to the contract of the
>interface but imlementing differently depending upon object type. The
>interface included a do, undo and redo method. This separated the do from
>the redo and enables you to create a null do with an operative redo.
>
>For objects such as textboxes, a change notification occurred via the
>standard events which created and stacked the command object as per normal,
>the system called the null do command because the assumption was that
>databinding would already have effected the change and subsequent undo /
>redo actions were implemented using specialised code that had knowledge of
>the bound control type being undone.
>
>I can't post code as it was for a commercial client but the process was
>pretty standard Command Pattern.


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
Reply With Quote
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      24th Mar 2005
Hi

What do you mean by initiated events and code initiated events?
Do you mean the event which is defined by the user code or by the
DataGrid's buildin event?
If so, I think we can add more argument in the User Code Event to indicate
the difference.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      24th Mar 2005

I mean if we're listening to the ColumnChanged event on a DataTable,
we don't know if the event was triggered because the user did
something in the bound grid or because some other code applied a
change to the table.

However, another colleague pointed out the grid we're using,
Infragistics UltraGrid, has change events we can use instead of the
DataTable events and this will provide for the necessary
differentiation in our case--grids are the only place we're using data
binding.

Thanks,

Sam


On Thu, 24 Mar 2005 08:33:03 GMT, v-(E-Mail Removed)
("Peter Huang" [MSFT]) wrote:

>Hi
>
>What do you mean by initiated events and code initiated events?
>Do you mean the event which is defined by the user code or by the
>DataGrid's buildin event?
>If so, I think we can add more argument in the User Code Event to indicate
>the difference.
>
>Best regards,
>
>Peter Huang
>Microsoft Online Partner Support
>
>Get Secure! - www.microsoft.com/security
>This posting is provided "AS IS" with no warranties, and confers no rights.


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
Reply With Quote
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      25th Mar 2005
Hi Samuel,

Thanks for your feedback.
I agree that if we want to check who fire the columnchanged event, we may
try to monitor the grid's related change event.
And thanks for your sharing the experience in the community.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WinForms and IsDirty Implementation Yosh Microsoft C# .NET 1 27th Oct 2005 12:20 AM
Command Pattern implementation with bound winforms controls? Samuel R. Neff Microsoft C# .NET 3 23rd Mar 2005 04:54 PM
Singleton design pattern implementation for VC .Net Ken Cattanach Microsoft VC .NET 1 26th Sep 2003 06:58 AM
Update Command / Data bound controls Problem Rob Williams Microsoft ADO .NET 1 2nd Sep 2003 07:20 PM
Is there a "duwamish" for .NET Winforms showing best practices for use of the BindingManager with bound controls? Timo Microsoft ADO .NET 1 23rd Aug 2003 02:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:57 PM.