I'm just learning C# (using Microsoft Visual C# 2005 Express Edition) and I'm having a bit of trouble with Windows Forms.

Here is what I want to happen.
  1. [frmClientManager] displays xml data in an Listview control
  2. A button on [frmClientManager] opens a new [frmClientEditor] form
  3. a) [frmClientEditor] adds data to the xml Database
    b) [frmClientEditor] refreshes the [frmClientManager] form by running a public function [frmClientManager.Read()]
    c) [frmClientEditor] closes itself

It might be easier to understand from code.

FORM: [frmClientEditor]

private frmClientManager otherForm;
private void btnSaveClient_Click(object sender, EventArgs e)


FORM: [frmClientManager]

private void frmClientManager_Load(object sender, EventArgs e)
private void btnNewClient_Click(object sender, EventArgs e)
public void Read()
// Code for Reading/Refreshing the xml Database
void NewClient()
frmClientEditor frmClientEditor = new frmClientEditor();

So, as I understand it, I need to be able to define the existing parent form [frmClientManager] from a child form [frmClientEditor].

Last year, while attempting a similar project in Visual Basic .NET 2003, I was able to achieve this using "Friend Events".

EQUIVALENT OF: [frmClientEditor]

Friend Event MyRefreshEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
RaiseEvent MyRefreshEvent(Me, New System.EventArgs)
RaiseEvent MyRefreshEvent(Me, New System.EventArgs)

Dim frmContacts As New frmContacts
RemoveHandler MyRefreshEvent, AddressOf frmContacts.refreshData_Handler
End Sub

EQUIVALENT OF: [frmClientManager]

Public Sub refreshData_Handler(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim frmAddContact As New frmAddContact
AddHandler frmAddContact.MyRefreshEvent, AddressOf Me.refreshData_Handler
End Sub

And on the side, I've got a few niggling random questions:
  • How do you create wizards for your programs, ie: Backup Data Wizard
  • My XML database was created in the solutions explorer, so the actual file sits in the Solution Directory. When my program is deployed, where does it go and how does my application know where to find it Does it sit in C:/Program Files/My App/database.xml
  • Is there a way to get an editable textbox into a ListView Control

Hope thats enough information! All help is much appreciated, Thanks Guys.



Re: Visual C# Express Edition Multiple Forms: Running a Function in the Main Form from the Child Form


It sounds like you should be able to add an event handler to your formClientEditor.

On your formClientEditor, set the save button's modifier to public.

Then in the formClientManger add this method:

Code Block

void formClienEditor_SaveClick(Object sender, EventArgs e)




Now in the NewClient method, add this after the Show() method:

Code Block
formClientEditor.btnSaveClient.Click += new EventHandler(formClienEditor_SaveClick);

Once this is done, after the save button is clicked, the program will run the save method in the formClientEditor, then run the saveClick method that you created.

Hope this helps.