Solved

Error with DataTable Transfer

Posted on 2006-11-28
2
166 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
Comment Utility
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
Comment Utility
Perfect!  Thanks So Much!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now