Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user moves items from one FlexGrid control to another
KeywordsFlexGrid, move items, drag drop
CategoriesControls
 
When the user clicks on grid data, enable or disable the "move right" and "move left" buttons depending on which items are selected. If an item is selected in the left list, enable the "move right" button. If an item is selected in the right list, enable the "move left" button.
 
' Enable the appropriate movement buttons.
Private Sub flxData_Click(index As Integer)
    cmdMoveRight.Enabled = (flxData(0).Row > 0)
    cmdMoveLeft.Enabled = (flxData(1).Row > 0)
End Sub
 
When the user clicks a move button, call subroutine MoveBetweenGrids to move the selected item from one grid to the other.
 
' Move items from the right grid to the left grid.
Private Sub cmdMoveLeft_Click()
    MoveBetweenGrids flxData(1), flxData(0)
End Sub

' Move items from the left grid to the right grid.
Private Sub cmdMoveRight_Click()
    MoveBetweenGrids flxData(0), flxData(1)
End Sub
 
Subroutine MoveBetweenGrids makes a new row in the destination grid, copies the item from the source to the destination grid, and deletes the original row.
 
' Move the selected row from one grid to the other.
Private Sub MoveBetweenGrids(ByVal flxFrom As MSFlexGrid, _
    ByVal flxTo As MSFlexGrid)
Dim from_row As Integer
Dim to_row As Integer
Dim c As Integer

    from_row = flxFrom.Row
    to_row = flxTo.Rows
    flxTo.Rows = to_row + 1

    ' Loop through the columns copying values.
    ' In this case there is only one column
    ' but it's done in a loop for more general
    ' programs.
    For c = 0 To 0
        flxTo.TextMatrix(to_row, c) = _
            flxFrom.TextMatrix(from_row, c)
    Next c

    ' Delete the original row.
    flxFrom.RemoveItem from_row

    ' Deselect the rows in the grids.
    flxFrom.Row = 0
    flxTo.Row = 0
    cmdMoveRight.Enabled = False
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated