【发布时间】:2016-11-09 08:16:24
【问题描述】:
我有一个 FormClosing 事件处理程序,它在操作时显示一个带有两个按钮是或否的消息框。 因此,如果用户单击“是”,那么它会使用 For 循环检查值,并在找到无效值时如何保持在相同的表单上而不打开新的表单并保留所有值。
我怎样才能做到这一点。
简化代码如图所示: (类代码位于 MainForm.vb 类代码使用的 EditDataForm.vb 中)
''' Closing Event that fired upon user closing the Form
Private Sub EditDataForm_FormClosing(sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show(Me, "Do you want to save your changes?", "Unsaved Changes!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
ButtonSave_Click(Me, e)
Else
Exit Sub 'Exit this Sub
End If
End Sub
''' Button Save Click Event
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
Dim rowIndex As Integer
Dim CheckDouble As Double
'' Leave the oth and 1th row
For rowIndex = 2 To masterDataGridView.RowCount - 1
If TypeOf(masterDataGridView.Rows(rowIndex).Cells("Val").Value) is String Then
Double.TryParse(masterDataGridView.Rows(rowIndex).Cells("Val").Value, CheckDouble)
If(CheckDouble <= 0) Then
MsgBox("Decimal Number Expect in place of:" & masterDataGridView.Rows(rowIndex).Cells("Val").Value & "at Row Number:" & rowIndex + 1, MsgBoxStyle.Critical, "FAILURE")
'''''''' HOW CAN I STAY ON THIS SAME FORM
Exit Sub
End If
End If
Next
''Other Save Methods etc...
End Sub
【问题讨论】:
标签: vb.net winforms event-handling msgbox