Validing on DataGridView

G

Guest

I was following the examples in the documentation but I think I am missing
something. When I detect an invalid input I set e.Cancel to True. The problem
is that in CellEndEdit I cannot cancel the error or clear the error text. I
have some lines that look like:

Private Sub dgvOrderItems_EditingControlShowing(ByVal sender As
Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles
dgvOrderItems.EditingControlShowing
e.CellStyle.BackColor = Color.Aquamarine
_editingControl = DirectCast(e.Control,
DataGridViewTextBoxEditingControl)
AddHandler _editingControl.TextChanged, AddressOf
dgvOrderItems_TextChanged
End Sub

Followed by the CellEndEdit handler:

Private Sub dgvOrderItems_CellEndEdit(ByVal sender As Object, ByVal
e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgvOrderItems.CellEndEdit
RemoveHandler _editingControl.TextChanged, AddressOf
dgvOrderItems_TextChanged
' Clear the error text
dgvOrderItems.Rows(e.RowIndex).ErrorText = String.Empty

The problem is that the text in the edit control is still the invalid input
that the user entered. If I click <ESC> I get into this handler but the text
in the edit control is still the invalid input. I would like to revert back
to what was in the cell before editing began. Any ideas? Maybe I need a
tutorial on the flow that happens after e.Cancel is set. Which events are
fired? What can I expect on the text?

Thank you.


Kevin
 
G

Guest

It appears that there is some interaction between the CellFormatting event
and the Validating event. In the formatting event I simply add $ via
ToString("c") and % via ToString("p2") but I was expecting to only see
numeric input in the validating event but I see the formatted values. Plus it
seems that validating is called for all of the columns/cells in the row not
just the editable ones during edit mode. I am a little lost on the sequence
of events for validating, formatting, and editing. Any suggestions would be
greatly appreciated.

Thank you.

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top