Solved

Flex Grid Cut and Paste

Posted on 2000-03-24
3
756 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

623 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