473,698 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MVC-Pattern in my C# GUI !?!

Hi NG !
For learning work with patterns I would like to add the MVC-Pattern in my
little application.
On my form (View) I have a TabController with 2 tabs. In each tab I would
like to have a datagrid, which should be updated after some changes. So this
two datagrids must implement my observer-interface. My class supportControl
would be the Model, which extends from my observable class.
Thats my theoretical understanding.. .now my questions to the implementation
in C#:

1.) The 2 Datagrids are the objects, which must be updated. Do I have to
create two classes (for each datagris one), which extends from
System.Windows. Forms.DataGrid and implements my observer interface ?
2.) My DataGrid on the main form would initialized by the classes i created
under point 1.) ???

Sorry this questions, but I'm not sure, if thats the right way of
implementation MVC !

Thanks and regards

Marcel Hug
Jan 2 '06 #1
10 5973
Marcel,
For learning work with patterns I would like to add the MVC-Pattern in my
little application. I have tried to implement the MVC-pattern as well, but I did not
completely succeed.
On my form (View) I have a TabController with 2 tabs. In each tab I would
like to have a datagrid, which should be updated after some changes. So this
two datagrids must implement my observer-interface. My class supportControl
would be the Model, which extends from my observable class.
Thats my theoretical understanding.. .now my questions to the implementation
in C#:

I did it as follows:
1/ I create my forms and I add some public properties and events. The
properties are used for setting and getting the data for the controls
(textboxes, datagrids, button-captions). The events are used for
handeling button-clicks, data-changes, etc.
1/ I create another class which I call the controller-class. This class
is the connection between the forms (my GUI) and the underlying code.
This class has methods like ShowUsers(), which gets a datatable with the
user-data from the data-layers and then creates a new instance of the
Users-form, sets the data to the form-properties and shows the form.
This class is also catching the events from the User-form.

So, an example, I have called the ShowUsers() methode on my controller
class. The Users-form has been displayed by this method. Now I can
change the data in the textboxes and other controls. When I click a
button (e.g. a Save button), the controller class catches the event. It
is then the controller class that handles the rest. The controller class
will get the adapted data from the form, save it to the database and
then return the changed data to the form.

You can also use eventargs to pass data from the form to the
controller-class.

I hope you understand what I'm doing. This is the way I implement my
kind of MVC-pattern and I must say that it works very well!

greetz,
Dries

Jan 2 '06 #2
"Marcel Hug" <ma************ ******@ATch.abb .com> a écrit dans le message de
news: eB************* *@TK2MSFTNGP14. phx.gbl...

| For learning work with patterns I would like to add the MVC-Pattern in my
| little application.

May I advise that you can't "add" MVC in an application, you really need to
design the application to use the MVC framework; but that may just be a
difference in how we say the same thing :-)

| On my form (View) I have a TabController with 2 tabs. In each tab I would
| like to have a datagrid, which should be updated after some changes. So
this
| two datagrids must implement my observer-interface. My class
supportControl
| would be the Model, which extends from my observable class.

You should not have anything other than visual controls on your forms, the
Controllers should be separate classes, instantiated in code outside of the
form.

You will also need to provide a set of wrapper classes that will allow you
to detect when you set the properties of your business classes, so that the
Controller can handle things like an Changing, or Changed event fired from
the "property".

As to the visual components on the form, if you want to avoid deriving from
the existing controls to implement the Observer pattern, these also need to
have wrapper classes that implement the Observer pattern and carry out the
Update method against the enclosed UI control.

You could also just use the data-aware nature of the existing controls to
replace teh Observer pattern, but write a Controller that catches the
Validating event of the controls so that you can enforce business rules when
leaving an edit control.

IMO, MVC is fairly well implemented, although not obviously, in the new .NET
data-aware controls.

I have written a series of articles on MVP (a sort of super MVC) on my
website www.carterconsulting.org.uk

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 2 '06 #3
Hello Marcel,
Hi NG !
For learning work with patterns I would like to add the MVC-Pattern in
my
little application.
On my form (View) I have a TabController with 2 tabs. In each tab I
would
like to have a datagrid, which should be updated after some changes.
So this
two datagrids must implement my observer-interface. My class
supportControl
would be the Model, which extends from my observable class.


Actually, you need neither an observer interface (C# is not Java -- use events),
nor should your model need to extend from any particular class. Your controller
should update the model, the model should expose events to signal state changes,
and your views should subscribe to those model events they care about. See
http://www.codeproject.com/csharp/mo...controller.asp for an introduction.

Cheers,
--
Joerg Jooss
ne********@joer gjooss.de
Jan 2 '06 #4
Joanna,
|| For learning work with patterns I would like to add the MVC-Pattern in my
|| little application.
|
| May I advise that you can't "add" MVC in an application, you really need
to
| design the application to use the MVC framework; but that may just be a
| difference in how we say the same thing :-)
I agree.

However! Using Refactoring & Refactoring To Patterns, surely one can *add*
the MVC pattern to an existing app that currently doesn't use the MVC
pattern?

http://www.refactoring.com/
http://www.industriallogic.com/xp/refactoring/

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
| "Marcel Hug" <ma************ ******@ATch.abb .com> a écrit dans le message
de
| news: eB************* *@TK2MSFTNGP14. phx.gbl...
|
|| For learning work with patterns I would like to add the MVC-Pattern in my
|| little application.
|
| May I advise that you can't "add" MVC in an application, you really need
to
| design the application to use the MVC framework; but that may just be a
| difference in how we say the same thing :-)
|
|| On my form (View) I have a TabController with 2 tabs. In each tab I would
|| like to have a datagrid, which should be updated after some changes. So
| this
|| two datagrids must implement my observer-interface. My class
| supportControl
|| would be the Model, which extends from my observable class.
|
| You should not have anything other than visual controls on your forms, the
| Controllers should be separate classes, instantiated in code outside of
the
| form.
|
| You will also need to provide a set of wrapper classes that will allow you
| to detect when you set the properties of your business classes, so that
the
| Controller can handle things like an Changing, or Changed event fired from
| the "property".
|
| As to the visual components on the form, if you want to avoid deriving
from
| the existing controls to implement the Observer pattern, these also need
to
| have wrapper classes that implement the Observer pattern and carry out the
| Update method against the enclosed UI control.
|
| You could also just use the data-aware nature of the existing controls to
| replace teh Observer pattern, but write a Controller that catches the
| Validating event of the controls so that you can enforce business rules
when
| leaving an edit control.
|
| IMO, MVC is fairly well implemented, although not obviously, in the new
..NET
| data-aware controls.
|
| I have written a series of articles on MVP (a sort of super MVC) on my
| website www.carterconsulting.org.uk
|
| Joanna
|
| --
| Joanna Carter [TeamB]
| Consultant Software Engineer
|
|
Jan 4 '06 #5
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> a écrit dans
le message de news: eL************* *@TK2MSFTNGP11. phx.gbl...

| However! Using Refactoring & Refactoring To Patterns, surely one can *add*
| the MVC pattern to an existing app that currently doesn't use the MVC
| pattern?

Certainly, but not by adding the extra functionality to a form class. IME,
refactoring a data-aware, RAD, "code on the form" application is usually
best achieved by a complete redesign :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 4 '06 #6
| best achieved by a complete redesign :-)
Which is the entire point behind Refactoring: "Improving the Design of
Existing Code". ;-)

Of course I am not trying to infer that it would be easy to add.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:uy******** ******@TK2MSFTN GP10.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> a écrit
dans
| le message de news: eL************* *@TK2MSFTNGP11. phx.gbl...
|
|| However! Using Refactoring & Refactoring To Patterns, surely one can
*add*
|| the MVC pattern to an existing app that currently doesn't use the MVC
|| pattern?
|
| Certainly, but not by adding the extra functionality to a form class. IME,
| refactoring a data-aware, RAD, "code on the form" application is usually
| best achieved by a complete redesign :-)
|
| Joanna
|
| --
| Joanna Carter [TeamB]
| Consultant Software Engineer
|
|
Jan 4 '06 #7
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> a écrit dans
le message de news: Oh************* *@TK2MSFTNGP09. phx.gbl...

| Which is the entire point behind Refactoring: "Improving the Design of
| Existing Code". ;-)
|
| Of course I am not trying to infer that it would be easy to add.

Heheh, if you think MVC is difficult, you wait until you do MVP, Model View
Presenter that is, not the MS type :-)

I have now implemented MVP in both Delphi and C#; C# 2.0 has made it sooo
much easier. The object linkable data-aware controls have also enabled me to
throw out all sorts of code that used to be necessary in Delphi.

Once you get to know how MVC or MVP work, it really does save so much
hassle; most of the forms in a good MVP system have no extra code apart from
that generated by the designer for placing the components on the form. MVP,
along with a good Object Persistence Framework have gotten us to the stage
where the only code we now write is business classes and logic; storage and
UI are already done and dusted.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 5 '06 #8
| Heheh, if you think MVC is difficult, you wait until you do MVP, Model
View
| Presenter that is, not the MS type :-)
Yea, I saw MVP on your site, I was going to add it to my short list of
things to investigate.

| I have now implemented MVP in both Delphi and C#; C# 2.0 has made it sooo
| much easier. The object linkable data-aware controls have also enabled me
to
| throw out all sorts of code that used to be necessary in Delphi.
Is the C# version of MVP available yet?

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:u7******** ******@TK2MSFTN GP14.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> a écrit
dans
| le message de news: Oh************* *@TK2MSFTNGP09. phx.gbl...
|
|| Which is the entire point behind Refactoring: "Improving the Design of
|| Existing Code". ;-)
||
|| Of course I am not trying to infer that it would be easy to add.
|
| Heheh, if you think MVC is difficult, you wait until you do MVP, Model
View
| Presenter that is, not the MS type :-)
|
| I have now implemented MVP in both Delphi and C#; C# 2.0 has made it sooo
| much easier. The object linkable data-aware controls have also enabled me
to
| throw out all sorts of code that used to be necessary in Delphi.
|
| Once you get to know how MVC or MVP work, it really does save so much
| hassle; most of the forms in a good MVP system have no extra code apart
from
| that generated by the designer for placing the components on the form.
MVP,
| along with a good Object Persistence Framework have gotten us to the stage
| where the only code we now write is business classes and logic; storage
and
| UI are already done and dusted.
|
| Joanna
|
| --
| Joanna Carter [TeamB]
| Consultant Software Engineer
|
|
Jan 5 '06 #9
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> a écrit dans
le message de news: uA************* @tk2msftngp13.p hx.gbl...

| Is the C# version of MVP available yet?

Due to copyright reasons with the companies that have paid for the
development of the code base, I can only really teach the design principles
on a consultancy basis - which I am more than willing to do :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8792
by: pysim | last post by:
Hi, I have a couple of general requests for pointers to python examples and design advice. I'm looking for examples of MVC-based GUI controls done in python (model-view-controller). Also, examples where something like a simulation model running in its own thread sends fast updates to a GUI in near real-time. The only examples I've seen, such as SimPy, wait until the model is finished running before outputting data.
6
1177
by: | last post by:
Hi all, Like to know if any one have implementated any enterprise .Net Solution using MVC Model? Is there any doc (whitepaper) or write up on this? Thanks. regard
6
2043
by: avlee | last post by:
Hello I am planning in my company to move to php.MVC framework - to create several big web applications. What are your opinions of this framework ? Is it the best MVC framework for PHP ? What are the pros and cons ? Best regards, Michal
4
1270
by: scott.w.white | last post by:
Looking at different MVC frameworks from many langauges from PHP to Python, I've concluded that the explosion of MVC frameworks is mainly due to undisciplined & unexperienced programmers. Nobody would argue about the separation of the layers because this is not the problem I have with it, if anything most implementations emphasis separation at the wrong places. The end solutions end up looking very mickey mouse. It's been long...
1
1975
by: Sean Quinn | last post by:
Hi all, This may have a really simple answer to it, but I can't seem to figure it out no matter how much I think about the problem. I'm working with an MVC framework (presently the most recent version of the Zend Framework 0.93, but no too committed with the project to prevent me from switching gears to a different framework), but I am having one heck of a time when attempting to reference static resources such as javascript scripts,...
3
1368
by: -pb- | last post by:
We are developing a Windows client using .NET 2.0 and C#. We have decided to use MVC based architechture due to its obvious advantages. This application shows data from database in a Grid. We want to add a functionality of Printing grid and export grid to XL sheet. I would like to know where will I have to code above functionalities? Should it be in view or controller? Any suggestion is well come.
2
1524
by: Richard Coltrane | last post by:
Hello, Can anyone point me in the direction of some good introductory resources to MVC and Web. I have looked up several resources on MVC in general (none of which have any code samples) but I dont get hw it applies to web. In a winforms app i can see how MVC plays out. I have 2(n) different views, something changes in one of them, so we fire off a message to notify the other to update. The makes senseto me because their both...
1
1961
by: shapper | last post by:
Hi, I was checking the new ASP.NET MVC Preview 4 features and I found the following: var dataTokens = new RouteValueDictionary(); dataTokens.Add("namespaces", new HashSet<string>( new string { "MyApp.Blog.Controllers", "MyApp.Forum.Controllers",
13
1408
by: Author | last post by:
I happened to see this asp.net MVC tutorial at http://www.asp.net/learn/mvc/tutorial-01-cs.aspx Indeed as the author says it is gonna look like classic ASP at the very beginning of this tutorial. I think form post with an action (which is classic asp style) like <form method="post" action="/Home/CreateNew">
0
13305
Airslash
by: Airslash | last post by:
Hello, this is my second article that I'm writing for bytes.com, and this time I wish to share some knowledge on how to test a custom ActionFilterAttribute for a controller in the ASP.NET MVC 2 Framework. I've been working with the Framework for a month now, comming from a Ruby on Rails background, and developed a special ActionFilter that performs authentication of users against our database using customized HTTP headers. The concept...
0
8673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7716
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.