Solved

Flex Grid Cut and Paste

Posted on 2000-03-24
3
732 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

16 Experts available now in Live!

Get 1:1 Help Now