View Single Post
  #2 (permalink)  
Old October 19th, 2011, 05:45 AM
avery11 avery11 is offline
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

I have made this sub procedure. Try by using it on Button click event in your code. Hope this will work as per your requirement.

Public Sub MoveUp(ByRef firstRow As System.Windows.Forms.DataGridViewRow, ByRef nextRow As System.Windows.Forms.DataGridViewRow)
'Create a temporary value
Dim temp As Object
Dim temp2 As Object

'Loop through each cell in the firstRow datagridview
Dim i As Integer
For i = 0 To firstRow.Cells.Count - 1
'If the cell isn't read only, then swap them.
If firstRow.Cells(i).ReadOnly = False Then
'use the temp object to swap the cell values.
temp = firstRow.Cells(i).Value
temp2 = nextRow.Cells(i).Value

firstRow.Cells(i).Value = temp2
nextRow.Cells(i).Value = temp
End If
End Sub
Reply With Quote