从单独的表单刷新UltraWinGrid

时间:2017-06-08 10:52:40

标签: vb.net forms winforms infragistics ultrawingrid

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

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

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

因为我使用的是ToolStripButton且表单使用了f.MdiParent = Me.MdiParent,所以我无法使用this answer here中使用的相同解决方案,因为没有DialogResultToolStripButton上,使用ShowDialog时无法使用MdiParents

还有其他方法可以达到这个目的吗?

2 个答案:

答案 0 :(得分:1)

这是一个简单的例子:

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

答案 1 :(得分:0)

你可以在不改变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