Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vb.net Datagridview RowValidating - Setting cell focus on error

86 views
Skip to first unread message

Rob W

unread,
Nov 16, 2009, 2:28:56 PM11/16/09
to
Greetings,

The code below never sets the current cell to the error location, allowing
user to correct the mistake (see below), though does display the error
message.
This is activated when they press tab to leave the row (RowValidating) and
the next row is populated with values from DefaultValuesNeeded

I was wondering where my logic and code have failed me, instead of setting
the focus to the cell containing the error it moves to the next row with the
default values set but the error logo and text displayed?

Thanks Rob
'Validation for day of weekends

Select Case DirectCast(currentRowToValidate.Cells("bookDate").Value,
DateTime).DayOfWeek

Case DayOfWeek.Saturday Or DayOfWeek.Sunday

Me.DataGridView1.Rows(e.RowIndex).ErrorText = "Error: Booking cannot be for
the weekend, please try again."

e.Cancel = True

DataGridView1.CurrentCell = Me.DataGridView1.Item(e.ColumnIndex, e.RowIndex)

Case Else

e.Cancel = False

End Select


Rob W

unread,
Nov 16, 2009, 2:47:49 PM11/16/09
to
I should also mention the datagridviewcell is a datetimepicker as created
from an article from the msdn website.

I also explicity tried using the column name without success (see below)
DataGridView1.CurrentCell = Me.DataGridView1.Item("bookDate", e.RowIndex)

"Rob W" <rob...@o2.co.uk> wrote in message
news:%23mmQPMv...@TK2MSFTNGP04.phx.gbl...

Rob W

unread,
Nov 17, 2009, 3:36:33 PM11/17/09
to
All working (so far) of course with e.cancel = true should stop the user
from leaving the row until the error is corrected.

So no need to try and manually set the row & cell focus.


"Rob W" <rob...@o2.co.uk> wrote in message

news:ebY59WvZ...@TK2MSFTNGP06.phx.gbl...

0 new messages