PC Review


Reply
Thread Tools Rate Thread

Datagrid/Dataset bindings

 
 
Rick
Guest
Posts: n/a
 
      8th Oct 2003
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
'----
 
Reply With Quote
 
 
 
 
Kris Langohr[MSFT]
Guest
Posts: n/a
 
      16th Oct 2003
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.

 
Reply With Quote
 
Jeff Shelby
Guest
Posts: n/a
 
      31st Oct 2003
"Rick" <(E-Mail Removed)> wrote in message news:<094401c38db7$c91eb3f0$(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset Data bindings Best practices? Neo Microsoft Dot NET 0 29th Apr 2005 09:34 PM
Typed dataset, bindings and endCurrentEdit =?Utf-8?B?bm9ybWRAb25saW5lLmtub3JyYXNzb2NpYXRlcy5j Microsoft Dot NET Framework Forms 1 24th Jan 2005 03:31 PM
Typed dataset, bindings and endCurrentEdit =?Utf-8?B?bm9ybWRAb25saW5lLmtub3JyYXNzb2NpYXRlcy5j Microsoft ADO .NET 0 10th Dec 2004 02:01 PM
ado.net dataset and bindings Mike Microsoft VB .NET 2 8th Dec 2003 01:03 AM
Dataset and Bindings dave@here.ca Microsoft ADO .NET 3 17th Sep 2003 12:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:00 AM.