DataGridView Undo/Redo

DataGridView Undo/Redo

Old forum URL: forums.lhotka.net/forums/t/1267.aspx


Sarosh posted on Tuesday, September 19, 2006

Hi!

Just started using CSLA 2.1 and need to create a simple Winform to maintain (Add/Delete/Save/ etc) lookup tables and allow n-level undo/redo functionality to it using a DataGridView Control

How should I go about this.

e.g. Have created two BO's

1] Project : Csla.BusinessBase<Project>

2] ProjectList : Csla.BusinessListBase<ProjectList, Project>

3] _projectList = ProjectList.GetProjectList();

4] BindingSource.DataSource = _projectList;

5] DataGridView.DataSource = BindingSource;

6] Users can Add, Delete, Save, Undo, Redo in the DataGridView

Undo/Redo should be able to handle not just changes in rows, columns but also handle New rows and Deleted rows. Is this possible?

Any help will really help!

Thanks.

Sarosh

 

RockfordLhotka replied on Tuesday, September 19, 2006

So ProjectList is your root object, containing child Project objects?

This was just discussed in another thread, yesterday I think. You need to:

  1. Create an instance of ProjectList
  2. Call BeginEdit on ProjectList
  3. Set your bindingsource.DataSource to your ProjectList

in that order!

Then in your Save click handler:

  1. Call bindingsource.EndEdit
  2. Call ApplyEdit on your ProjectList
  3. Call Save on your ProjectList
  4. Rebind by using the steps in the first list

And in your Cancel click handler:

  1. Call bindingsource.CancelEdit
  2. Call CancelEdit on your ProjectList
  3. Rebind by using the steps in the first list

Sarosh replied on Tuesday, September 19, 2006

Hi!

>>So ProjectList is your root object, containing child Project objects?

Yes it is the root object and contains child project objects.

I understand Save and Cancel but what about code in the Undo and Redo click handlers?

Sarosh

Brian Criswell replied on Tuesday, September 19, 2006

This has been discussed a bit in the past.  I think the consensus was that you would need to maintain a separate stack for the undo and redo items.

Sarosh replied on Tuesday, September 19, 2006

Hi!

Not sure what you mean here but are you saying that I need another stack type object to handle this outside of  my BO's ?

Sarosh

RockfordLhotka replied on Tuesday, September 19, 2006

Ahh, I see. Yes, like Brian points out, this is outside the scope of CSLA, and there's another thread where some solutions were discussed (using the command design pattern as I recall).

CSLA can handle "undo" quite nicely. But there's no concept of "redo" at all. And even the "undo" isn't granular - it operates at a per-object level. See Chapter 3 for details.

Sarosh replied on Tuesday, September 19, 2006

Hi!

Thank you all for the info. this helped a lot.

I will search for "command design pattern" to see what I can find.

Thanks again.

Sarosh

Copyright (c) Marimer LLC