Copying and pasting content of a single cell in flexgrid to another cell.

Copying  and pasting content of a single cell in flexgrid to another cell. How is that done? Thanks
zachvaldezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fds_fatboyCommented:
Please explain more - do you mean just copying a value from one cell to another cell or do you mean copying all properties. Or do you mean actually moving values/properties between cells and the clipboard?

0
zachvaldezAuthor Commented:
Just the value of the cell
and pasting to another cell.
0
fds_fatboyCommented:
So you mean copy - not copy and paste.

FlexGrid1.TextMatrix(DestRow,DestCol) = FlexGrid1.TextMatrix(SourceRow,SourceCol)

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

zachvaldezAuthor Commented:
Copy and Paste too.
Also how will I use the variables -DestRow,Descol,sourcerow,sourcol
I assume it is the value of the cell selected to be copied and paste. Thnks!
0
PePiCommented:
ok... first off, you have to go to the cell where the original value is. I am assuming the selection mode for your grid is set to flexSelectionFree. now, once you are on the cell you want to copy, you press a key (let's say CTRL+C, you can code this on the key down event of the grid). you save the the value of the cell to a global variable like:

    strBuffer = FlexGrid1.TextMatrix(.RowSel, .ColSel)

You then move your cursor to the destination cell where you want to paste the copied data. again, this can be triggered by pressing a key (CTRL+V, also to be coded in the key down event of the grid). you then transfer the data on the string buffer onto the new cell like:

    FlexGrid1.TextMatrix(.RowSel, .ColSel) = strBuffer
0
zachvaldezAuthor Commented:
Private Sub MSHFlexgrid1_KeyDown(KeyCode As Integer, Shift As Integer)
   strBuffer = MSHFlexgrid1.TextMatrix(MSHFlexgrid1.RowSel, MSHFlexgrid1.ColSel)
    MSHFlexgrid1.TextMatrix(MSHFlexgrid1.RowSel, MSHFlexgrid1.ColSel) = strBuffer
End Sub

this did not paste  
0
fds_fatboyCommented:
Zachvaldez - of cours it didn't - reread PePi's statement.

Anyway you didn't answer my question - but I have come to the conclusion you want to copy and past using the clipboard.
This allows true copy and paste with the clipboard. Try it you can copy out of another object (textbox, notepad, ie etc), into the flexgrid using the clipboard and where possible vice versa


Private Sub FlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyC Or KeyCode = vbKeyInsert) And (Shift And vbCtrlMask) Then
        'Copy
        Clipboard.Clear
        With FlexGrid1
            Clipboard.SetText .TextMatrix(.Row, .Col)
        End With
    ElseIf ((KeyCode = vbKeyV) And Shift And vbCtrlMask) Or ((KeyCode = vbKeyInsert) And Shift And vbShiftMask) Then
        'Paste
        If Clipboard.GetFormat(vbCFText) Then
            With FlexGrid1
                .TextMatrix(.Row, .Col) = Clipboard.GetText
            End With
        End If
    End If
End Sub

0
PePiCommented:
or if you don't want to use the Clipboard and stick with the string buffer, then do this:

Private Sub FlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyC Or KeyCode = vbKeyInsert) And (Shift And vbCtrlMask) Then
        'Copy
        With FlexGrid1
           strBuffer = .TextMatrix(.Row, .Col)
        End With
    ElseIf ((KeyCode = vbKeyV) And Shift And vbCtrlMask) Or ((KeyCode = vbKeyInsert) And Shift And bShiftMask) Then        'Paste
        If Clipboard.GetFormat(vbCFText) Then
            With FlexGrid1
                .TextMatrix(.Row, .Col) = strBuffer
            End With
        End If
    End If
End Sub
0
PePiCommented:
i'm lazy at typing... wrong Copy & Paste... lol. below is the correct code

Private Sub FlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyC Or KeyCode = vbKeyInsert) And (Shift And vbCtrlMask) Then
        'Copy
        With FlexGrid1
           strBuffer = .TextMatrix(.Row, .Col)
        End With
    ElseIf ((KeyCode = vbKeyV) And Shift And vbCtrlMask) Or ((KeyCode = vbKeyInsert) And Shift And bShiftMask) Then        'Paste
        With FlexGrid1
            .TextMatrix(.Row, .Col) = strBuffer
        End With
    End If
End Sub
0
zachvaldezAuthor Commented:
BOth worked wonderfully!
I know realizzed that I need to put the function in a menu so that the control C and CNTRL V may not work as this was the clipboard approach which I know only realized. RAther it should  be in the right click of the mouse.

THANks
0
fds_fatboyCommented:
Do you need to know how to do this?
0
fds_fatboyCommented:
Anyway if you do here it is:

-------------------------------------------------------------------

In your form designer - press Ctrl+E to start the menu editor
Create a new top level menu
    Caption: flexgrid
    Name: mnuFlexgrid
    Visible: False
    Shortcut: (None)
    All other fields leave as default
Create a child menu under mnuFlexgrid
    Caption: &Copy
    Name: mnuFlexgridCopy
    Visible: True
    Shortcut Ctrl+C
    All other fields leave as default
Create another child menu under mnuFlexgrid
    Caption: &Paste
    Name: mnuFlexgridPaste
    Visible: True
    Shortcut Ctrl+P
    All other fields leave as default

----------------------------------------------------

replace the previous code with this:

Private Sub FGCopy()
    Clipboard.Clear
    With FlexGrid1
        Clipboard.SetText .TextMatrix(.Row, .Col)
    End With
End Sub

Private Sub FGPaste()
    If Clipboard.GetFormat(vbCFText) Then
        With FlexGrid1
            .TextMatrix(.Row, .Col) = Clipboard.GetText
        End With
    End If
End Sub
Private Sub FlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyC Or KeyCode = vbKeyInsert) And (Shift And vbCtrlMask) Then
        FGCopy
    ElseIf ((KeyCode = vbKeyV) And Shift And vbCtrlMask) Or ((KeyCode = vbKeyInsert) And Shift And vbShiftMask) Then
        FGPaste
    End If
End Sub

Private Sub mnuFlexgridCopy_Click()
    FGCopy
End Sub

Private Sub mnuFlexgridPaste_Click()
    FGPaste
End Sub

Private Sub FlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = vbRightButton Then
        PopupMenu mnuFlexgrid
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zachvaldezAuthor Commented:
That's great!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.