0
我有一個FormClosing事件處理程序,在操作時顯示帶有兩個按鈕的消息框是或否 因此,如果用戶單擊是,那麼它使用For循環檢查值並找到無效價值它如何保持這種形式而不用打開新的一個保留所有的VALUES。無效的數據斷言後防止窗體關閉
我該如何做到這一點。
簡化的代碼被如下所示: (類代碼駐留在EditDataForm.vb這是通過MainForm.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
添加e.Cancel =真如你所說後。 Like: ButtonSave_Click(Me,e) e.Cancel = True 它與預期的相同。謝謝。 – user3051677
你似乎混合了C#和VB.NET語法:)。分號不在VB.NET中使用,比較運算符爲'='。 –