从单独的窗体刷新 UltraWinGrid

Refresh an UltraWinGrid from a separate form

我有一个包含客户列表的表单和另一个可以添加客户的表单。当我从 fCustomerList 打开 fAddCustomer 表单时,我使用以下代码调用它:

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

fCustomerAdd,我有一个 ToolStripButton 来添加客户。当表单关闭时,我需要刷新 fCustomerList 上的 UltraWinGrid 以自动查看列表中的新数据。

因为我使用的是 ToolStripButton 并且表单使用 f.MdiParent = Me.MdiParent,所以我不能使用与 相同的解决方案,因为没有 DialogResultToolStripButton 上,并且在使用 MdiParents 时不能使用 ShowDialog

还有其他方法可以实现吗?

你可以在不改变 DataSource 传递的情况下实现这一点,正如@Plutonix 建议的那样:

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

这是一个简单的例子:

' ... 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