robtyketto
Member
- Joined
- Jul 23, 2009
- Messages
- 23
- Programming Experience
- Beginner
Greetings,
I have a datagridview which is populated from the SelectionChangeCommitted event of the combobox.
The datagridview contains both bound and unbound data columns (see below).
There is a button on the form to allow add a row via
Then I populate the new row with default values in the DataGridView1.DefaultValuesNeeded event.
I didn't expect the behaviour of when ANY cell on the new row has a value added then a new row is created.
Ideally I would like to use the RowValidated/RowValidating event and when the user Leaves the row via TAB key then it would validate and create a new row ONLY if all the data was ok.
Is this the default behaviour? can this be changed i.e. not trigger creation of a new row if a cell is populated.
Thanks
Rob
I have a datagridview which is populated from the SelectionChangeCommitted event of the combobox.
The datagridview contains both bound and unbound data columns (see below).
VB.NET:
'Bind specific columns ONLY
'Colums 0 AND 7 are unbound columns
DataGridView1.DataSource = bookingData.Tables("bookings")
DataGridView1.Columns(1).DataPropertyName = bookingData.Tables("bookings").Columns(0).ToString
DataGridView1.Columns(2).DataPropertyName = bookingData.Tables("bookings").Columns(1).ToString
DataGridView1.Columns(3).DataPropertyName = bookingData.Tables("bookings").Columns(2).ToString
DataGridView1.Columns(4).DataPropertyName = bookingData.Tables("bookings").Columns(3).ToString
DataGridView1.Columns(5).DataPropertyName = bookingData.Tables("bookings").Columns(4).ToString
DataGridView1.Columns(6).DataPropertyName = bookingData.Tables("bookings").Columns(5).ToString
There is a button on the form to allow add a row via
VB.NET:
DataGridView1.AllowUserToAddRows = True
Then I populate the new row with default values in the DataGridView1.DefaultValuesNeeded event.
VB.NET:
Private Sub dataGridView1_DefaultValuesNeeded(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) _
Handles DataGridView1.DefaultValuesNeeded
With e.Row
.Cells("bookingDate").Value = New Date(Now.Year, Now.Month, Now.Day)
.Cells("startTime").Value = New Date(Now.Year, Now.Month, Now.Day, 8, 0, 0)
.Cells("endTime").Value = CType(e.Row.Cells("startTime").Value, DateTime).AddHours(1)
.Cells("booker").Value = bookersName
.Cells("phoneExt").Value = phoneNum
.Cells("bookingsFrequency").Value = "1"
End With
End Sub
I didn't expect the behaviour of when ANY cell on the new row has a value added then a new row is created.
Ideally I would like to use the RowValidated/RowValidating event and when the user Leaves the row via TAB key then it would validate and create a new row ONLY if all the data was ok.
Is this the default behaviour? can this be changed i.e. not trigger creation of a new row if a cell is populated.
Thanks
Rob
Last edited: