Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# general approach question 1

Status
Not open for further replies.

Tve

Programmer
May 22, 2000
166
FR
Hi,

This may seem a basic question, but I want to be sure I get this right. I'm writting my first C# form and I still need to understand a few basics.

First question:

My form displays a multicolumn listview to display files that are added by the user. I've created a class for thes e files as I need to extract information from the file through external programs. When the user drops files on the listview, I create an instance of the class (which does the data extraction) and then I display a subset of the information to the user (he doesn't need to know all information from the file).

I C#, do I need to create an array member to store the instances of the file class (I will require non-displayed data when the users clicks "OK")?

Second question:

When VS creates a callback, it looks something like:
[tt] button1_Click(object sender, System.EventArgs e)[/tt]
and it works as expected, but how should I call this method from within another method? More explicitly, I do not know what to provide as event argument as in
[tt]this.button1_Click(this.button1,???)[/tt]

Thanks,


AD AUGUSTA PER ANGUSTA

Thierry
 
an "arrayList as ClassName" would be good but an array member would do
you can call a buttun click from elsewhere in the class with
buttonName.PerformClick()

Age is a consequence of experience
 
Thanks litton1!



AD AUGUSTA PER ANGUSTA

Thierry
 
On my second question (callback):

I would like to call the callback of a CheckBox, but it does not appear to have the PerformClick() method (as buttons do) that litton1 mentionned.

Any other option?



AD AUGUSTA PER ANGUSTA

Thierry
 
ok... boooooo!

take the functionality out of the button1_click method if you need to call it from mutliple places.

private void DoSomething()
{
MessageBox.Show("Something");
}

private void button1_click(object sender, EventArgs e)
{
DoSomething();
}

private void checkbox1_CheckChange(object sender, CheckEventArgs e)
{
DoSomething();
}
 
Thanks JurkMonkey... I suppose I desserved that one.

I had of course thought of your solution, but somehow I was looking for a more elegant option. I imagine that I should get back down to real life, live with the quirks and concentrate on getting things working.



AD AUGUSTA PER ANGUSTA

Thierry
 
Thierry,

You will want to become familiar with the Model-View-Controller design pattern. It allows you to work with data application wide.

This allows you to update information and use it cleanly. You can then update your GUI based on the most current data in your system.

While most beginners don't realize the importance of design pattens it can help you become a strong developer in a short amount of time if you start learning early.

Keep plugging at it and you will be successful - we're always here to help.
 
Actually the data/model should update the View whenever it get's changed. And the pattern used for this is the Observer-pattern. Which you can implement with events in .net or with methods like in Java. I like the events way better.

Christiaan Baes
Belgium

"My new site" - Me
 
I agree with the Observer pattern to update GUI. You have to be careful implementing this pattern though. You are better to register your GUI component with the class that throws the event rather than having the component throw the event and various GUI pieces attaching to it independently. This is because trying to follow a string of events after the fact becomes complicated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top