Hoping someone can help me on this, I have the AllowUserToAddRows properties on the datagridview set to True.
The problem seems to be that on the SQL table the 2nd column in the table is "Allow Null" = False.
If I go to add a new row, you can type in the details in the first column, but when you go to tab to the next column which doesn't allow the nulls, it seems to try and add the row first and then moves to the next column, but then gives an error about not allowing rows in the 2nd column.
I have found a way around this is to go to a new row and type in the 2nd column first, this adds a new row with the other columns are blank in it, then you essentially edit the new row to add the remainder of the column values.
I have tried a function I found on MSDN which uses the DataGridView.Columns.DisplayIndex = 0 / 1 / 2... etc for each of the columns in the table. I thought this way it would use my workaround but force the user to type the 2nd column first by displaying it in DisplayIndex 0.
This function didn't actually rearrange the columns unfortunately, so I couldn't test it. Code is below in case it helps:
I think it might be best if I could stop the row from being added until the user fills in all of the first before clicking on an ADD / UPDATE button, because there could be a case that a table has more than one field with Allow Nulls set to False.
Does anyone know how to stop it adding the row until a button has been clicked, but still enabling the AllowUserToAddRows = True, so that the user doesn't have to fill out text boxes?
Or if it can't be done that way, do you put in bindingsource.addnew first and then bingdingsource.update? Do you have to bind the text boxes to the datasource?
Thanks.
The problem seems to be that on the SQL table the 2nd column in the table is "Allow Null" = False.
If I go to add a new row, you can type in the details in the first column, but when you go to tab to the next column which doesn't allow the nulls, it seems to try and add the row first and then moves to the next column, but then gives an error about not allowing rows in the 2nd column.
I have found a way around this is to go to a new row and type in the 2nd column first, this adds a new row with the other columns are blank in it, then you essentially edit the new row to add the remainder of the column values.
I have tried a function I found on MSDN which uses the DataGridView.Columns.DisplayIndex = 0 / 1 / 2... etc for each of the columns in the table. I thought this way it would use my workaround but force the user to type the 2nd column first by displaying it in DisplayIndex 0.
This function didn't actually rearrange the columns unfortunately, so I couldn't test it. Code is below in case it helps:
VB.NET:
Private Sub AdjustColumnOrder()
With DataGridView2
'.Columns("CustomerID").Visible = False
.Columns("RefCode").DisplayIndex = 0
.Columns("RefType").DisplayIndex = 1
.Columns("RefDescription").DisplayIndex = 2
.Columns("Active").DisplayIndex = 3
End With
End Sub
I think it might be best if I could stop the row from being added until the user fills in all of the first before clicking on an ADD / UPDATE button, because there could be a case that a table has more than one field with Allow Nulls set to False.
Does anyone know how to stop it adding the row until a button has been clicked, but still enabling the AllowUserToAddRows = True, so that the user doesn't have to fill out text boxes?
Or if it can't be done that way, do you put in bindingsource.addnew first and then bingdingsource.update? Do you have to bind the text boxes to the datasource?
Thanks.