Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello everyone,

 

I have created a MultiDocument application in C#. One that has one main form and a few child forms. What I am trying to do is that since these child forms access a database, I need to keep them updated. I already have the main parent form using a timer and polling the database for changes. When a change is detected I need to reload the forms. How can I reload a child form. Using the refresh method only redraws the form, I need to reload the form so that the method that updates the data on the form is executed. One of the problems is that the parent form does not create every one of it's child forms. A child form will also create a form with the parent set to it's parent. I hope I didn't lose you. Basically, the parent form does not instantiate every one of it's child forms. Ideally I would use a foreach(Form f in this.MdiChildren) to cycle through each form and execute a reload method. Each forms load method will reload the data, but I don't know how to trigger an event in a foreach loop. Any and all suggestions are greatly appreciated.

 

Anyone have any suggestions on how to accomplish this??????

 

Thanks,

Kendal

  • Administrators
Posted

You could provide a public function in each form which reloads the data and call this from your for...each loop.

This approach could cause a lot of database activity and network traffic though if you have lots of users with lots of forms refreshing too frequently.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

How would I do that? I have tried it so far by creating a public method call Reload() in each form. In the main form I use

 

foreach(Form f in MdiChildren)

{

f.Reload();

}

 

but it will not work. Reload is only available from an instance of the specific class, not from the form class. Am I wrong???? That is just from my thinking, and my thinking is kind of whack some times.....lol. What would you suggest?????

 

Thanks again,

Kendal

  • Administrators
Posted (edited)

probably the OO way of doing things would be to create an interface (IReload or similar) and get each of your child forms to implement this.

 

//interface declaration
public interface IReload
{
void Reload();
}

 

in each child form use the following idea as the form declaration (if you are not inheriting from a System.windows.Forms.Form then adjust accordingly

public class Form1 : System.Windows.Forms.Form, IReload

 

then you could create a for each loop similar to the following

foreach (Form f in MdiChildren)
		{
		IReload ir = f as IReload;
		if(ir != null)
			ir.Reload();
		}

 

this way if a child doesn't need to be forced to refresh - don't implement the interface. If it does implement it and provide the Reload method and it should work :-\

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...