Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In MSFlexGrid , how can I copy a cell to paste somewhere else ?

Status
Not open for further replies.

snr

Programmer
Oct 8, 2001
78
0
0
US
I want to copy a particular cell from the populated MSflexgrid and paste in a text box.
How that can be done ?

Thanks
 
Dim SomeVariable As Variant
With MSFlexGrid1
.Row =
.Col =
SomeVariable = .Text
End With
 
no no no Not that way
I can't use copy-paste in MSFlexGrid.... so what can be an alternative for that ?
I should be able to paste that cell.text anywhere .......



 
Do you want to programmatically cope the text somewhere? If so, you can use the above code to get the value and then:

txtBox.Text = SomeVariable

If you want the user to be able to copy and paste, it is a little more complicated but the same idea. Can you elaborate before I post code?
 
Flexgrid (grdDep) is on Child form of MDI Form (frmMain) With COPY, PASTE and SELCT ALL in edit menu.
Code:
Private Sub grdDep_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MouseDownPopUp grdDep, Button, Shift, X, Y, frmMain.mnuEdit
End Sub
'
Public Sub MouseDownPopUp(objCtl As Control, Button As Integer, intShift As Integer, _
                        sngX As Single, sngY As Single, objmenu As Object)
    Dim strTypeName As String
    
    strTypeName = UCase$(TypeName(objCtl))
    If Button = vbRightButton Then
        On Error Resume Next
            objCtl.Enabled = False ' Disable othere pop-up
            objCtl.Enabled = True
            Select Case strTypeName
            Case "MSFLEXGRID", "MSHFLEXGRID"
                '* Select proper Row and Column
                objCtl.Row = objCTL.MouseRow
                objCtl.Col = objCTL.MouseCol
            End Select
            objCtl.SetFocus
            If Err = 0 Then
                objCtl.Parent.PopupMenu objmenu
            End If
        On Error GoTo 0
    End If
End Sub
' frmMain Menu Code
Private Sub mnuEditCopy_Click()
    Dim strDescription As String, strName As String
    Dim strTypeName       As String
    Dim strCopy As String
    On Error Resume Next
    strTypeName = UCase$(TypeName(ActiveForm.ActiveControl))
    strName = ActiveForm.ActiveControl.Name
    If strTypeName = "MSFLEXGRID" Or strTypeName = "MSHFLEXGRID" Then
        strCopy = ActiveForm.ActiveControl.Text
        If Len(strCopy) > 0 Then
            Clipboard.SetText strCopy, vbCFText
        End If
    Else
        Clipboard.SetText ActiveForm.ActiveControl.SelText, vbCFText
    End If
    strDescription = Err.Description
    
End Sub
Private Sub mnuEditPaste_Click()
    Dim strDescription As String, strName As String
    Dim strTypeName       As String
    Dim strPaste        As String
    On Error Resume Next
        strTypeName = UCase$(TypeName(ActiveForm.ActiveControl))
        strName = ActiveForm.ActiveControl.Name
        If strTypeName = "MSFLEXGRID" Or strTypeName = "MSHFLEXGRID" Then
            strPaste = Clipboard.GetText(vbCFText)
            ActiveForm.ActiveControl.Text = strPaste
        Else
            ActiveForm.ActiveControl.SelText = Clipboard.GetText(vbCFText)
        End If
        strDescription = Err.Description
    On Error GoTo 0
    
End Sub
Private Sub mnuEditSelectAll_Click()
    Dim strDescription As String, strName As String, _
        intErr As Integer
    Do
        On Error Resume Next
            strName = ActiveForm.ActiveControl.Name
            If Err Then Exit Do
            
            ActiveForm.ActiveControl.SelStart = 0
            If Err Then Exit Do
            
            ActiveForm.ActiveControl.SelLength = Len(ActiveForm.ActiveControl.Text)
            If Err Then Exit Do
            
            Clipboard.SetText ActiveForm.ActiveControl.SelText, vbCFText
            If Err Then Exit Do
        
    Exit Do: Loop
    
    strDescription = Err.Description
    On Error GoTo 0
End Sub
Compare Code (Text)
Generate Sort in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top