Vb.net [2008] Datagridview Bound to dataset behaviour issues.

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
 
R

Rob W

To summarise I want to allow the user to add a row to the datagridview with
default values (which it currently does) but ONLY allow
ONE row to be added at a time via a button.

Pressing the same button will validate the row.

Finally the process will repeat add row/validate row.

Is this possible by toggling the allusertoaddrows option?
 

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