Solved

Flex Grid Cut and Paste

Posted on 2000-03-24
3
735 Views
Last Modified: 2008-03-10
I have a problem with a flex grid, I don't know how to retreive the coordinates that the user is in when he/she selects a cell. I need this information to do cut and paste.

If you have any algorithms for cut and paste for a flex grid please send it to me.
0
Comment
Question by:aomega
3 Comments
 
LVL 19

Expert Comment

by:daveamour
ID: 2653752
Private Sub Form_Load()
MSFlexGrid1.AddItem "1" & vbTab & "2" & vbTab & "3" & vbTab & "4"
MSFlexGrid1.AddItem "1" & vbTab & "2" & vbTab & "3" & vbTab & "4"
MSFlexGrid1.AddItem "1" & vbTab & "2" & vbTab & "3" & vbTab & "4"

End Sub

Private Sub MSFlexGrid1_Click()
MsgBox "X=" & MSFlexGrid1.Row & vbCrLf & "Y=" & MSFlexGrid1.Col
End Sub

Does this help?
0
 

Expert Comment

by:FarewellIIArms
ID: 2653791
Hi,

have a look at the ColSel & RowSel Properties, help says these are for:

You can use these properties to select a specific region of the MSHFlexGrid programmatically, or to read the dimensions of an area that the user selects into code.

0
 
LVL 14

Accepted Solution

by:
mcrider earned 30 total points
ID: 2654367
Here you Go...

The two subroutines are CopyFromGrid and PasteToGrid.  Basically they work this way... You have a flexgrid called "MSFlexGrid1".

A user highlights a set of cells and then hits CTRL-C, clicks on another cell and hits CTRL-V.

In the keypress event of the MSFlexGrid1 object, you intercept the CTRL-C and CTRL-V and call the subroutines like this:

'_______________________________________________________________________________
    Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
            Case 3 'CTL-C (Copy)
                CopyFromGrid MSFlexGrid1
                KeyAscii = 0
            Case 22 'CTL-V (Paste)
                PasteToGrid MSFlexGrid1
                KeyAscii = 0
        End Select
    End Sub
'_______________________________________________________________________________



Here are the subroutines:

'_______________________________________________________________________________
    Public Sub CopyFromGrid(GridObject As Object, _
        Optional StartRow As Variant, Optional EndRow As Variant, _
        Optional StartCol As Variant, Optional EndCol As Variant)
        'THIS FUNCTION WILL COPY THE SELECTED CELLS FROM A FLEXGRID TO THE CLIPBOARD
        'IF StartRow AND StartCol ARE NOT SPECIFIED, THE CURRENT GRID ROW/COL ARE USED
        'IF EndRow AND EndCol ARE NOT SPECIFIED, THE CURRENT GRID ROWSEL/COLSEL ARE USED
        Dim Row As Integer
        Dim Col As Integer
        Dim sRow As Integer
        Dim sCol As Integer
        Dim eRow As Integer
        Dim eCol As Integer
        Dim R1 As Integer
        Dim R2 As Integer
        Dim C1 As Integer
        Dim C2 As Integer
        Dim ClipString As String
        ClipString = "[GRIDCLIP]" + vbFormFeed
        With GridObject
            sRow = .Row: If IsMissing(StartRow) = False Then sRow = StartRow
            sCol = .Col: If IsMissing(StartCol) = False Then sCol = StartCol
            eRow = .RowSel: If IsMissing(EndRow) = False Then eRow = EndRow
            eCol = .ColSel: If IsMissing(EndCol) = False Then eCol = EndCol
            If sCol > eCol Then
                C1 = eCol: C2 = sCol
            Else
                C1 = sCol: C2 = eCol
            End If
            If sRow > eRow Then
                R1 = eRow: R2 = sRow
            Else
                R1 = sRow: R2 = eRow
            End If
            For Row = R1 To R2
                For Col = C1 To C2
                    ClipString = ClipString + .TextMatrix(Row, Col) + vbVerticalTab
                Next Col
                ClipString = ClipString + vbFormFeed
            Next Row
            Clipboard.Clear
            Clipboard.SetText ClipString, vbCFText
        End With
    End Sub
    Public Function PasteToGrid(GridObject As Object, Optional StartRow As Variant, Optional StartCol As Variant) As Boolean
        'THIS FUNCTION WILL PASTE THE CLIPBOARD CONTENTS OF A CopyFromGrid CALL
        'IF StartRow AND StartCol ARE NOT SPECIFIED, THE CURRENT GRID ROW/COL ARE USED
        'THIS FUNCTION WILL RETURN TRUE IF SUCCESSFUL
        Dim Row As Long
        Dim Col As Long
        Dim sRow As Long
        Dim sCol As Long
        Dim ClipString As String
        Dim ClipLine As String
        Dim Cindex As Long
        On Error Resume Next
        PasteToGrid = False
        ClipString = Clipboard.GetText
        If Not (Left$(ClipString, 11) = "[GRIDCLIP]" + vbFormFeed) Then Exit Function
        ClipString = Mid$(ClipString, 12)
        With GridObject
            sRow = .Row: If IsMissing(StartRow) = False Then sRow = StartRow
            sCol = .Col: If IsMissing(StartCol) = False Then sCol = StartCol
            Row = sRow
            Do While Not (ClipString = "")
                Cindex = InStr(1, ClipString, vbFormFeed)
                ClipLine = Left$(ClipString, Cindex - 1)
                ClipString = Mid$(ClipString, Cindex + 1)
                Col = sCol
                Do While Not (ClipLine = "")
                    Cindex = InStr(1, ClipLine, vbVerticalTab)
                    .TextMatrix(Row, Col) = Left$(ClipLine, Cindex - 1)
                    If Not (Err = 0) Then Exit Function
                    ClipLine = Mid$(ClipLine, Cindex + 1)
                    Col = Col + 1
                Loop
                Row = Row + 1
            Loop
        End With
        PasteToGrid = True
    End Function
'_______________________________________________________________________________


By the way, don't you think this is worth more than 30 points... ;-)


Cheers!.)


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now