I'm getting very confused trying to make my "Delete" button work. All
looked ok at first, with:
Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles DeleteButton.Click
Dim pos As Integer = GetPosition()
If MsgBox("Delete record " + Str(pos) + " (" + StatusString(pos)
+ ")?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
TextBox1.AppendText("Deleting " + Str(pos) + " (" +
StatusString(pos) + ")" + Chr(13) + Chr(10))
DataSet11.Tables("table").Rows(pos).Delete()
End If
End Sub
Function GetPosition() As Integer
GetPosition = Me.BindingContext(DataSet11, "table").Position
End Function
Function StatusString(ByVal pos As Integer) As String
Dim drsi As DataRowState =
DataSet11.Tables("table").Rows(pos).RowState
Dim drss As String = ""
If (drsi And 1) <> 0 Then drss = drss + "Detached "
If (drsi And 2) <> 0 Then drss = drss + "Unchanged "
If (drsi And 4) <> 0 Then drss = drss + "Added "
If (drsi And 8) <> 0 Then drss = drss + "Deleted "
If (drsi And 16) <> 0 Then drss = drss + "Modified"
StatusString = drss
End Function
The msgbox says "Delete record 0 (Unchanged)?", and after clicking Yes,
the values in the textboxes, bound to various fields in "table", do
change to show those in the second record (ie record 1). But when I
click again on Delete, the msgbox now says "Delete record 0 (Deleted)?",
and clicking Yes has no effect.
Even worse, I've found that after getting to the last record with...
Private Sub TopButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TopButton.Click
Me.BindingContext(DataSet11, "table").Position = _
Me.BindingContext(DataSet11, "table").Position.MaxValue
End Sub
..then back to the second-from-last with...
Private Sub DownButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles DownButton.Click
Me.BindingContext(DataSet11, "table").Position -= 1
End Sub
..(second-from-last rec shows ok), then Delete, the msgbox says "Delete
record 88 (Unchanged)?", which is good. But after deleting it, (and the
display going back to show rec 0 again for some reason) and then going
to the last record again and clicking Delete again, the msgbox says
"Delete record 88 (Deleted)?"!!
(I have a 'debug' text box which shows the statuses of the last few
records ('rows', I should say), and that clearly shows record 88 as
Deleted, and 89 as Unchanged.)
Whew! Thanks, if anybody's read this far. I'm confused. I'm clearly
not getting something.
Help Please?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!