Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error with DataTable Transfer

Posted on 2006-11-28
2
Medium Priority
?
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

705 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