Solved

Flex Grid Cut and Paste

Posted on 2000-03-24
3
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 61
to transfer string from C lanaguage to VBA 4 77
Access 2013 combo box not working 3 59
Need Nag Screen for Reboot if system up time is over 14 days 12 81
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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