Click here to Skip to main content
14,387,927 members
Rate this:
Please Sign up or sign in to vote.
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

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100