Best way of designing Win Forms Call backs

G

Guest

I have a .Net 2 WinForm app which allow multi-windows to co-exist (in task
bar). They are all spawned from a main-form.

(i.e., Form A can start Forms B,C,D,E)

2 questions about call-backs

Question 1) Forms B,C,D contains DataGridView, which I need to make sortable
on multiple columns/fields (which is not a built in .Net functionality, I
believe). I need a new Modal dialog to be spawned from Forms B,C,D to allow
users to select sort fields and orders and then on closing the dialog, the
gridView in Forms B,C,D need to be refreshed with the new sort order selected
in the modal dialog.

What is the best way (of doing call-backs) from modal-Dialog X back to Forms
B,C,D?

Should I have
1) "Abstract" class MyDataGridForm with an abstract method called
ReSortGridView()
2) Have Forms B, C, D inherit from this abstract Form MyDataGridForm?
3) Define the Modal Sort selection dialog's constructor as taking in
MyDataGridForm as a parameter?

Any better ways of doing this?

Question 2) Ideally, it would be nice that for every new Form spawned off, a
"Window" navigation menuitem is added. So each form would need a "handle" on
to all forms spawned. What is the best way of doing this?
 
C

Collin

First I would post your question in two different post.

I can only give advice to the first question. Use should use a
Behavioral Pattern like Mediator Pattern. Create a global mediator
object (FormLeader) that has events. When a Form A starts the
childrens is register it with the FormLeader object so the children
can talk and listen for events. When someone clicks on data grid in a
child, it notify the FormLeader of that action. The FormLeader takes
care of creating the ReOrder Dialog. When the ReOrder dialog is
closed the FormLeader raise an event to notify anyone that is
listening that a re-order has occured.

<http://en.wikipedia.org/wiki/Mediator_pattern>
<http://www.dofactory.com/Patterns/PatternMediator.aspx>

I hope this put you on the right track.
 
M

Marius Horak

Patrick said:
3) Define the Modal Sort selection dialog's constructor as taking in
MyDataGridForm as a parameter?

YES. KEEP IT SIMPLE!!!!
Even better you can use the grid as a parameter (or property).
Question 2) Ideally, it would be nice that for every new Form spawned
off, a "Window" navigation menuitem is added. So each form would
need a "handle" on to all forms spawned. What is the best way of
doing this?

ArrayList

MH
 
M

Marius Horak

Collin said:
I can only give advice to the first question. Use should use a
Behavioral Pattern like Mediator Pattern. Create a global mediator
object (FormLeader) that has events. When a Form A starts the
childrens is register it with the FormLeader object so the children
can talk and listen for events. When someone clicks on data grid in a
child, it notify the FormLeader of that action. The FormLeader takes
care of creating the ReOrder Dialog. When the ReOrder dialog is
closed the FormLeader raise an event to notify anyone that is
listening that a re-order has occured.

OMG!!! I need a master degree to understand this.
Hold on!!! I have a master degree in computing!!!

What's wrong with having somthing simple? Property or parameter will do.


MH
 

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