Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error with DataTable Transfer

Posted on 2006-11-28
2
Medium Priority
?
176 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 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