Solved

Error with DataTable Transfer

Posted on 2006-11-28
2
170 Views
Last Modified: 2010-04-23
I have a strange error...

Situation:
I have two DataTables (dtLinkedList and dtUnLinkedList)
I have two DataGrids (dgLinked and dgUnLinked)

I want to click a button and add items from one DataTable and DataGrid to the other DataTable and DataGrid

but when I have added more than 2 or 3 items from the dtUnLinkedList to the dtLinkedList , it just keeps adding the same item over and over again.



My Code

            Dim LinkedRow As DataRow = dtLinkedList.NewRow
            LinkedRow(0) = Me.dgUnLinked.Item(Me.dgUnLinked.CurrentRowIndex, 0)
            LinkedRow(1) = Me.dgUnLinked.Item(Me.dgUnLinked.CurrentRowIndex, 1)
            dtLinkedList.Rows.Add(LinkedRow)
            dtUnLinkedList.Rows.RemoveAt(Me.dgUnLinked.CurrentRowIndex)
            Me.dgLinked.Refresh()
            Me.dgUnLinked.Refresh()
            Me.dgLinked.CurrentRowIndex = 0
            Me.dgUnLinked.CurrentRowIndex = 0



HELP!
0
Comment
Question by:lgropper
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18029619
It sounds as though dgUnlinked is sorted.  Its .CurrentRowIndex will return the index of the row IN THE GRID.  The underlying datatable will not be sorted: its index will be in a different order.  So this

   dtUnLinkedList.Rows.RemoveAt(Me.dgUnLinked.CurrentRowIndex)

may remove from the datatable the wrong record.  Replace that line with something like this

   BindingContext(dtUnLinkedList).RemoveAt(BindingContext(dtUnLinkedList).Position)

Roger
0
 

Author Comment

by:lgropper
ID: 18031383
Perfect!  Thanks So Much!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question