R
Rob W
Greetings,
I have the functionality upon a button press to loop around the rows in the
datagrid view and where the checkbox is true then delete the row (see code
below).
It never deletes all those marked and when I use debug via printing
statements within the loop it randomly seems to skip a row.
I'm not sure if this is because I remove a row from the datagridview
datasource and thus the datagridviewrow count has now changed.
Line tracing shows entering RowValidating/RowValidation but I didn't see
anything strange happening there to impact the looping.
I don't delete via dataAdaptor as the datagridview does not map onto a
single table directly, instead I call bookingDeletion function form a class
which executes a delete SQL statement.
Can anyone please suggest why it does not loop through every single
datagridviewrow in the datagridview?
The looping code is below:-
The full code can be seen here:- http://pastebin.com/m3469f2a
'Loop around each row in datagridview
For Each booking As DataGridViewRow In DataGridView1.Rows
'Is cell value of selected is TRUE and name the same as login
If (booking.Cells("name").Value.Equals(bookersName) AndAlso
booking.Cells("selectColumn").Value = "True") Then
'Remove from database
Dim deleteBooking As New bookingsSession
If deleteBooking.bookingDeletion(cboRoom.SelectedValue,
booking.Cells("bookDate").Value, _
booking.Cells("startTime").Value, booking.Cells("endTime").Value) = True
Then
'Remove booking from datagridview
'DataGridView1.Rows.Remove(booking)
bookingsdata.Tables("bookings").Rows.Remove(DirectCast(booking.DataBoundItem,
DataRowView).Row)
bookingsdata.Tables("bookings").AcceptChanges()
End If
ElseIf (Not booking.Cells("name").Value.Equals(bookersName) AndAlso
booking.Cells("selectColumn").Value = "True") Then
'Highlight which bookings cannot be removed as not made by the user
MessageBox.Show("Warning: You are unable to delete the booking made on " _
& "the " & DirectCast(booking.Cells("bookDate").Value, DateTime).Date _
& " at " & CType(booking.Cells("starttime").Value,
DateTime).ToString("HH:mm") _
& " to " & CType(booking.Cells("endtime").Value, DateTime).ToString("HH:mm")
_
& " as booking was made by someone else.", "Warning: Unable to cancel
booking", _
MessageBoxButtons.OK)
booking.Cells("selectColumn").Value = "False"
End If
Next 'Retrieve next datgridviewrow for expection
Thanks
Rob
I have the functionality upon a button press to loop around the rows in the
datagrid view and where the checkbox is true then delete the row (see code
below).
It never deletes all those marked and when I use debug via printing
statements within the loop it randomly seems to skip a row.
I'm not sure if this is because I remove a row from the datagridview
datasource and thus the datagridviewrow count has now changed.
Line tracing shows entering RowValidating/RowValidation but I didn't see
anything strange happening there to impact the looping.
I don't delete via dataAdaptor as the datagridview does not map onto a
single table directly, instead I call bookingDeletion function form a class
which executes a delete SQL statement.
Can anyone please suggest why it does not loop through every single
datagridviewrow in the datagridview?
The looping code is below:-
The full code can be seen here:- http://pastebin.com/m3469f2a
'Loop around each row in datagridview
For Each booking As DataGridViewRow In DataGridView1.Rows
'Is cell value of selected is TRUE and name the same as login
If (booking.Cells("name").Value.Equals(bookersName) AndAlso
booking.Cells("selectColumn").Value = "True") Then
'Remove from database
Dim deleteBooking As New bookingsSession
If deleteBooking.bookingDeletion(cboRoom.SelectedValue,
booking.Cells("bookDate").Value, _
booking.Cells("startTime").Value, booking.Cells("endTime").Value) = True
Then
'Remove booking from datagridview
'DataGridView1.Rows.Remove(booking)
bookingsdata.Tables("bookings").Rows.Remove(DirectCast(booking.DataBoundItem,
DataRowView).Row)
bookingsdata.Tables("bookings").AcceptChanges()
End If
ElseIf (Not booking.Cells("name").Value.Equals(bookersName) AndAlso
booking.Cells("selectColumn").Value = "True") Then
'Highlight which bookings cannot be removed as not made by the user
MessageBox.Show("Warning: You are unable to delete the booking made on " _
& "the " & DirectCast(booking.Cells("bookDate").Value, DateTime).Date _
& " at " & CType(booking.Cells("starttime").Value,
DateTime).ToString("HH:mm") _
& " to " & CType(booking.Cells("endtime").Value, DateTime).ToString("HH:mm")
_
& " as booking was made by someone else.", "Warning: Unable to cancel
booking", _
MessageBoxButtons.OK)
booking.Cells("selectColumn").Value = "False"
End If
Next 'Retrieve next datgridviewrow for expection
Thanks
Rob