By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,684 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,684 IT Pros & Developers. It's quick & easy.

Datagrid/Dataset bindings

P: n/a
I'm trying to have a code removing selected rows in a
datagrid from the underlying dataset.
Because the DataGrid can be sorted the row numbers do not
match, so I wrote this code but for some reason it still
removing the wrong lines.

Any help will be greatly appreciated.
'----
Dim o As Object
Dim indexArray As New SortedList()
Dim bm As BindingManagerBase = BindingContext
(DataGrid1.DataSource, DataGrid1.DataMember)
Dim i As Integer
Dim j As Integer = 0
For i = 0 To DataGrid1.DataSource.rows.count - 1
If DataGrid1.IsSelected(i) Then
j += 1
indexArray.Add(j, i)
End If
Next
For j = indexArray.Count To 1 Step -1
DataGrid1.Select(indexArray(j))
MsgBox("j:" & j & " indexArray(j):" &
indexArray(j) & " bm.Position:" & bm.Position)
bm.RemoveAt(bm.Position)
Next
Dim dt As DataTable
dt = DataGrid1.DataSource.GetChanges()
DataGrid1.DataSource.AcceptChanges()
dt.RejectChanges()
DataGrid2.DataSource = dt
'----
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Rick,

I tried the code you supplied on both VS.Net 2002 and VS.Net 2003 and in
both cases the code did exactly what it is supposed to do based on your
description. The rows that I multi-select in the grid are removed from the
dataset and show up in the secondary table. In your experience what rows
are being deleted that shouldn't be.
Kris
VB Data QA Team

This posting is provided "AS IS" with no warranties and confers no rights.

Nov 20 '05 #2

P: n/a
"Rick" <sp*********@noway.com> wrote in message news:<09****************************@phx.gbl>...
DataGrid1.Select(indexArray(j))
MsgBox("j:" & j & " indexArray(j):" &
indexArray(j) & " bm.Position:" & bm.Position)
bm.RemoveAt(bm.Position)


I think you are having problems because "Select" doesn't change the
current position in the grid so bm.Position probably isn't changing.
If you replace

DataGrid1.Select(indexArray(j))

with

DataGrid1.CurrentIndex = indexArray(j)

you might get better results.

HTH

-JLS
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.