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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CUT AND PASTE PICTURE FROM MSFLEXGID 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
not for me...

possible to cut picture from a msflexgrid cell and paste in other cell, with left click button of mouse?
 
sal21 / 2009luca - what have you tried so far? Show here your effort to solve your issue.

PS. And why do you use 2 login names?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Sorry me Andy,
no idea to create code for drag and drop, never used
 
Did you try to Google anything?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Here's an example. I am not including much in the way of explanation, as it seems you never really pay much attention to that. As ever it is an EXAMPLE of how to do this, not a bespoke piece of code for your particular situation. Nor does it cover niceties such as aborting, or dropping in or signalling areas of the control you don't want to drop in

Code:
[COLOR=blue]Option Explicit
Dim drgImage As Picture
Dim srcRow As Long
Dim srcCol As Long

Private Sub Form_Load()
    [COLOR=green]' Set up a trivial msflexgrid with an image from an imagelist[/color]
    MSFlexGrid1.Rows = 4
    MSFlexGrid1.Cols = 4
    MSFlexGrid1.Row = 3
    MSFlexGrid1.Col = 3
    Set MSFlexGrid1.CellPicture = ImageList1.ListImages(1).Picture
End Sub

[COLOR=green]'MSFlexgrid DragMode property should be 0 - vbDragManual. Generally this is the default.[/color]
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = vbLeftButton Then
        With Me.MSFlexGrid1
            If .CellPicture <> 0 Then
                .DragIcon = .CellPicture
                ' capture source cell info
                Set drgImage = .CellPicture
                srcRow = .Row
                srcCol = .Col
                .Drag vbBeginDrag [COLOR=green]'start a drag operation.[/color]
            End If
        End With
    End If
End Sub

Private Sub MSFlexGrid1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
    [COLOR=green]' Allow default control behaviour to highlight potential target cell[/color]
    If Source Is Me.MSFlexGrid1 Then
        MSFlexGrid1.Col = MSFlexGrid1.MouseCol
        MSFlexGrid1.Row = MSFlexGrid1.MouseRow
    End If
End Sub

Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
    If Source Is Me.MSFlexGrid1 Then
        With Me.MSFlexGrid1
            Set .CellPicture = drgImage [COLOR=green]' copy source image into target[/color]
            
            .Row = srcRow
            .Col = srcCol
             Set .CellPicture = Nothing [COLOR=green]' this is a cut and paste, so delete image in source cell[/color]
             [COLOR=green]' Rehighlight cell we dropped on as that is generally expected behaviour[/color]
             .Row = .MouseRow
             .Col = .MouseCol
        End With
    End If
End Sub
[/color]
 
Tks strongm,
but i cannot test now.
 
Guess that's also the case for, e.g.:

thread222-1814206
thread222-1814146
thread222-1813837
thread222-1813768

all fairly recent threads started by you that have been left hanging. Appreciate that you may be busy, but so are the people who provide help here, and the repeated behaviour of asking questions, and then leaving them open (in the sense that we have no idea if you have seen the help, whether the help was of any use, or no response to questions seeking additional info from you) gives the appearance that you think your time is more valuable than our time.

And once people begin to get that impression, the less likely they will be to carve out some of their own valuable time to help you out. Just saying.
 
tested.
only one...

have error in : .DragIcon = .CellPicture

but i have commented the line in error and work!
Tks
 
Odd. Due to a quirk, that shouldn't have generated an error, but properly it should be

Set .DragIcon = .CellPicture
 
Yep, that'll be because the image you are using in the flexgrid isn't actually an icon.

You can fix this by changing

[tt]Set MSFlexGrid1.CellPicture = ImageList1.ListImages(1).Picture[/tt]

to

[tt]Set MSFlexGrid1.CellPicture = ImageList1.ListImages(1).ExtractIcon[/tt]
 
And again, as in many other posts mentioned here by strongm, no recognition of helpful post by sal21 / 2009luca with the use of a purple star.

mintjulep may be right... :-(

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top