p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   how to move rows in a datagrid with VB (http://p2p.wrox.com/showthread.php?t=85119)

garrdub September 21st, 2011 03:19 PM

how to move rows in a datagrid with VB
 
I'm enhancing an older app and have be working with ItemCommands to move rows in the datagrid up or down. Can anyone guide me to the best way to do this with examples? Any help is greatly appreciated.

avery11 October 19th, 2011 05:45 AM

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.

Code:
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
Next
End Sub

eileenmary October 20th, 2012 04:00 AM

I have done this code but it is in c#,so will it help you?

manuka honey


All times are GMT -4. The time now is 12:56 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.