Click here to Skip to main content
15,887,304 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello experts,

I want to copy a row from Datagridview1 to Datagridview2 based on the Value in Datagridview1.
Here is what I tried. But I didn't get through

VB
For Each dgvdr As DataGridViewRow In dgvShow.Rows
             If dr("FEITEM").ToString().Trim() = strItem Then
               Dim index As Integer = DataGridView2.Rows.Add(TryCast(dgvdr.Clone(), DataGridViewRow))
               'DataGridView2.Rows.Add(TryCast(dgvdr.Clone(), DataGridViewRow))
               ' DataGridView2.Rows.Add(dgvdr)
               For Each o As DataGridViewCell In dgvdr.Cells

                 DataGridView2.Rows(index).Cells(o.ColumnIndex).Value = o.Value
                 dgvdr.Cells(0).Value = False

               Next
             End If
           Next


Could someone help me achieve this?
Posted
Comments
Ralf Meier 7-May-15 14:06pm    
At which Position in your Code do you transfer any value into 'dr' ...?
I think, that is the mistake ...
sudevsu 8-May-15 10:22am    
That's not a mistake. for some reason my code is nor posted fully. I have value in dr("FEITEM") and it gets through the if condition
Maciej Los 9-May-15 17:04pm    
At the first look this line: Dim index As Integer = DataGridView2.Rows.Add(TryCast(dgvdr.Clone(), DataGridViewRow)) should cause error.
sudevsu 11-May-15 9:29am    
No it is not. I don't get error there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900