473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Datagrid/Dataset bindings

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
2 1098
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tom Gao | last post by:
Hello, We are having a recurring problem of a typed dataset that we have in a form dissapearing from the VS designer and all bindings being lost. The dataset is defined in another component and...
1
by: Junkguy | last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete" button on a form and achieve the same functionality as hitting the "delete" key on the keyboard for the selected row of...
2
by: John Smith | last post by:
Hey folks, I'm writing a Windows application which has many forms which have Datagrids on them to display data. These datagrids will not be editable in anyway. They are there to just view the...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
0
by: Johann Blake | last post by:
I have a dataset that I bind to two different datagrids. The dataset contains 2 tables. One is the main table used to store what I call session data which includes a Country field where the ID of a...
6
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on...
2
by: Nu2ASP.NET | last post by:
What I am trying to do is essentially 'flip' the bits, when the user clicks in the checkbox. For example, if the CheckBox appears checked, and the user un-checks it, I want the underlying data...
1
by: AliRezaGoogle | last post by:
Dear members, I have a datagrid and a textbox on my form. I bound both of them to a common datasource( an arbitrary datatable). When I change a text inside textbox I expect that value of same...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.