Harambe
Harambe

Reputation: 423

Refresh an UltraWinGrid from a separate form

I've got a form with a list of customers and another form where customers can be added. When I open the fAddCustomer form, from fCustomerList, I'm calling it using this code:

Dim f As New Form
f = New fAddCustomer(con, False)
f.MdiParent = Me.MdiParent
f.Show()

On fCustomerAdd, I've got a ToolStripButton to add the customer. When the form is closed, I need to refresh the UltraWinGrid that I have on fCustomerList to view the new data on the list automatically.

Because I'm using a ToolStripButton and the form uses f.MdiParent = Me.MdiParent, I can't use the same solution that was used in this answer here, as there is no DialogResult on a ToolStripButton, and you can't use ShowDialog when using MdiParents.

Is there any other way I can achieve this at all?

Upvotes: 0

Views: 139

Answers (2)

Idle_Mind
Idle_Mind

Reputation: 39142

Here's a simple example:

' ... in fCustomerList ...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim f As New fAddCustomer(con, False)
    f.MdiParent = Me.MdiParent
    AddHandler f.FormClosed, AddressOf f_FormClosed
    f.Show()
End Sub

Private Sub f_FormClosed(sender As Object, e As FormClosedEventArgs)
    ' ... refresh your UltraWinGrid ...
End Sub

Upvotes: 1

David
David

Reputation: 2324

One that you could achieve this without changing the DataSource passing as @Plutonix suggested is to do something like this:

Private Sub fAddCustomer_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing

Try
    If Application.OpenForms.OfType(Of fCustomerList).Any Then
       Application.OpenForms("fCustomerList").Close()
            Dim f As New fCustomerList()
            f.MdiParent = Me.MdiParent
            f.Show()
        End If

    Catch ex As Exception
        Debug.WriteLine(ex.Message)

    End Try
End Sub

Upvotes: 0

Related Questions