我正在使用一个具有 2 个窗口窗体的项目,一个带有超网格的家庭窗体,显示一些数据,另一个用于向其_dd数据。我想在添加数据表单关闭时刷新超网格,但目前无法这样做。
我需要使form_closing
子例程添加数据表单成为Public Shared Sub
,以允许我使用加载数据的主页窗体上的子例程获取ShowDialog.OK
值,以便它知道是否刷新它。但是,因为它是共享子,所以我无法使用Me.Dispose
.我该如何解决这个问题?
Private Sub fHome_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' This is where the UltraGrid gets it's data from
If fAdd.ShowDialog() = DialogResult.OK Then
uwgDisplay.DataSource = Nothing
displayData()
' addData form is open, then get the data from the database (dont refresh it)
Else
displayData()
' if add data form is closed, then refresh the data
End If
Me.Location = New Point(0, 0)
End Sub
这是添加表单上的表单结束子
Public Shared Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Globals.savedValue = False Then
Dim closeBox As MsgBoxResult
closeBox = MsgBox("Exit without saving?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If closeBox = MsgBoxResult.Yes Then
Me.Dispose()
ElseIf closeBox = MsgBoxResult.No Then
e.Cancel = True
Exit Sub
End If
Else
Me.Dispose()
End If
End Sub
在两条Me.Dispose()
行上,我被告知
Me 仅在实例方法中有效
你的陈述
"我需要使添加数据表单form_closing子例程 公共共享子允许我获取 ShowDialog.OK。
不正确。无需共享 FormClosing 方法即可获取 DialogResult
Private _myform As frmFoo
Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
If _myform Is Nothing Then _myForm = New frmFoo
If _myform.ShowDialog = DialogResult.OK Then
'do something
End If
End Sub