Now, from another MDI Child, the user selects a button which opens a window allowing them to add a new record to the system, this is simply a form and a add button... when the add button is clicked, a message box informs them that the new record is added.

My problem is that all MDI children will now need to be closed and reopened by the user for the record to be updated... how I would I go about triggering a refresh of all the MDI children to make sure that when a record is added, the new values are reflected across the application?

Recommended Answers

All 5 Replies

This is a solution I created in one of my projects.

Create a public method on each of the MDI childs.
In that method, clear all controls and recall InitializeComponent and then recall the forms load event.
Like so:

Public Function ReloadForm() As Boolean
   Try
      Me.Hide()
      Me.Controls.Clear()
      InitializeComponent()
      Form1_Load(Form, New System.EventArgs)
      Me.Show()
   Catch ex As Exception
      Return False
   End Try

   Return True
End Function

You can call that method from any other form:

If Not Form1.ReloadForm() Then
   MessageBox.Show("Failure to reload form","Minor error", .......)
End If
Try
            Me.Hide()
            Me.Controls.Clear()
            InitializeComponent()
            frmMain_Load(Form, New System.EventArgs)
            Me.Show()
        Catch ex As Exception
            Return False
        End Try

        Return True
    End Function

Error 1 Name 'frmMain_Load' is not declared
Error 2 'Form' is a type and cannot be used as an expression.

Error 1: Is the MDI child form called frmMain? I would assume that's the name of the MDI parent form.
Call the load method of the same form the code is in. Ie, it will reload itself.

Error 2: Replace "Form" with "Me"

awtz it will close then open again?zzz is there another way?

Sure there is.
You can remove the lines "Me.Hide" and "Me.Show".
That will refresh the form without hiding it first.

The only reason I added them was to avoid any "blinking" side-effects. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.