R
Rob W
Greetings,
I have a datagridview bound to a dataset upon selection of a combobox.
If the combobox selection populate the datagridview a button is made visible
which allows a new row to be added (DataGridView1.AllowUserToAddRows = True)
on the click event.
The new rows contain default values within DataGridView1.DefaultValuesNeeded
and sets the selection to the SECOND column using code on the BUTTON click
event:-
DataGridView1.CurrentCell.Selected = False
DataGridView1.Rows(DataGridView1.RowCount - 1).Cells(1).Selected = True
DataGridView1.CurrentCell = DataGridView1.SelectedCells(0)
Now my headaches start, I would like at this point to set
DataGridView1.AllowUserToAddRows = FALSE but as Im unsure the order of
events It always errors on the selection criteria as the index is invalid.
Where can I safely switch off the AllowlUserToAddRows to FALSE (add new
button sets the option to ON and then uses the code above to select cell
focus)?
I have validation routines for columns e.g.
currentRowToValidate.Cells("activity").FormattedValue in the RowValidating
event, however if I set the AllowUserToAddRow to FALSE am I right in
thinking this will never run?? Press tab or enter will simply move around
the controls and not trigger the event?
I was thinking perhap just validate the row on a button press (Add new row
button then toggles over to save row functionality?) passing in the current
row selection.
Or could I use an event of the datatable to trigger the datagridview
rowvalidating event as the dataviewgrid is bound?
Very difficult to explain so hope I've made some sense
Thanks
Rob
I have a datagridview bound to a dataset upon selection of a combobox.
If the combobox selection populate the datagridview a button is made visible
which allows a new row to be added (DataGridView1.AllowUserToAddRows = True)
on the click event.
The new rows contain default values within DataGridView1.DefaultValuesNeeded
and sets the selection to the SECOND column using code on the BUTTON click
event:-
DataGridView1.CurrentCell.Selected = False
DataGridView1.Rows(DataGridView1.RowCount - 1).Cells(1).Selected = True
DataGridView1.CurrentCell = DataGridView1.SelectedCells(0)
Now my headaches start, I would like at this point to set
DataGridView1.AllowUserToAddRows = FALSE but as Im unsure the order of
events It always errors on the selection criteria as the index is invalid.
Where can I safely switch off the AllowlUserToAddRows to FALSE (add new
button sets the option to ON and then uses the code above to select cell
focus)?
I have validation routines for columns e.g.
currentRowToValidate.Cells("activity").FormattedValue in the RowValidating
event, however if I set the AllowUserToAddRow to FALSE am I right in
thinking this will never run?? Press tab or enter will simply move around
the controls and not trigger the event?
I was thinking perhap just validate the row on a button press (Add new row
button then toggles over to save row functionality?) passing in the current
row selection.
Or could I use an event of the datatable to trigger the datagridview
rowvalidating event as the dataviewgrid is bound?
Very difficult to explain so hope I've made some sense
Thanks
Rob