Solved

Error with DataTable Transfer

Posted on 2006-11-28
2
167 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set form below another form 3 35
VB.Net - ReportViewer Windows Form many reports 2 24
DataGridView does not show data rows correctly in vb.net 2013 3 31
vb.net checkbox 7 41
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

22 Experts available now in Live!

Get 1:1 Help Now