我有一个带有客户列表的表单,还有可以添加客户的另一种表格。当我打开fAddCustomer
表单时,从fCustomerList
开始,我使用此代码来调用它:
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
,所以我无法使用此处答案中使用的相同解决方案,因为ToolStripButton
上没有DialogResult
,并且在使用时不能使用ShowDialog
MdiParents
。
我有什么其他方法可以实现吗?
这是一个简单的示例:
' ... 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
您可以实现此目标的情况,而不会像@plutonix所建议的那样更改DataSource
通过:
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