Hello,
I wonder if someone can help me please?
I have a datagridview bound to a dataset and additions are permitted in the DataGridView.
Assuming that I'm in 'Add Mode' (I'm in a cell of the bottom row) I wish to test the contents of a cell in the new row on exit (from that cell, NOT from the new row). If the test fails, I want the Add to be cancelled.
I want everything in the add row to vanish. I want the grid to go back to the current last existing row. How do I do this please?
My current code for the checking is:
Basically I want to add the command(s) where the xxxxxxxxxxxxx is to set the grid back to the current last existing row.Code:Private Sub dgvAccessLevels_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvAccessLevels.CellValidating If (e.ColumnIndex = 2) Then Try If e.FormattedValue = String.Empty Then xxxxxxxxxxxxx e.Cancel = True Exit Sub ElseIf Not IsNumeric(e.FormattedValue) Then MessageBox.Show("Please Enter numeric Value", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error) dgvAccessLevels.CurrentCell.Value = DBNull.Value xxxxxxxxxxxxx e.Cancel = True Exit Sub ElseIf e.FormattedValue > 5 Then MessageBox.Show("Please Enter a Value Between 0 and 5", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error) dgvAccessLevels.CurrentCell.Value = DBNull.Value xxxxxxxxxxxxx e.Cancel = True Exit Sub End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End If End Sub
Any help would be appreciated.
Thank you.


Reply With Quote