Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-01-2009
Member
 
Join Date: Dec 2008
Posts: 10
Move Rows of Datagridview In VB.Net

Hello Friends,

How can i Move Rows of Datagridview In VB.Net ?
Actually I am not using this feature in my application but just for some additional knowledge I want to know this.

Thanks.
Reply With Quote
  #2  
Old 22-01-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Move Rows of Datagridview In VB.Net

I can suggest a simple logic,

Temp = A

A = B

B = Temp

This should swap and will involve one less memory transfer per swap.
Reply With Quote
  #3  
Old 22-01-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Move Rows of Datagridview In VB.Net

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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Move Rows of Datagridview In VB.Net"
Thread Thread Starter Forum Replies Last Post
How to use datagridview readonly cell Ground 0 Windows Software 3 29-07-2009 12:44 PM
Merging duplicate names not rows copy rows into new workbook each time VBA Excel 2003 awkwardsmile Software Development 2 09-07-2009 08:57 AM
.net datagridview mouse position Jevin Software Development 2 29-06-2009 06:12 PM
How to resize cell in DataGridView Ebadaah Software Development 3 10-06-2009 06:54 PM
Difference Between DataGrid and DataGridView In VB.Net Gallard Software Development 3 17-01-2009 05:08 PM


All times are GMT +5.5. The time now is 12:29 AM.