MSFLEXGRID drag the picture from cell, and realese i a new cell?

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by sal21 »

MSFLEXGRID drag the picture from a cell, and realese i a new cell?

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by HansV »

I'm sorry, i cannot help you with this.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by sal21 »

HansV wrote:
23 Sep 2021, 16:33
I'm sorry, i cannot help you with this.
no prob!
Tks in orther case

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by SpeakEasy »

This example (non-production code,) needs a form with an MSFlexgrid and a picturebox (which you can set .Visible=False)

Code: Select all

Option Explicit

' Assumes msflexgrid has at least 4 rows
Private Sub Form_Load()
    With MSFlexGrid1
    .RowHeight(1) = 800
    .RowHeight(2) = 800
    .RowHeight(3) = 800
        .Row = 1
        .Col = 1
        .Text = "Example"
    Set MSFlexGrid1.CellPicture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\beany.bmp") ' You might want a different imnage, perhaps from an ImageList
    End With
End Sub

Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
    Dim oldrow As Long
    Dim oldcol As Long
    
    With MSFlexGrid1
        Set .CellPicture = Nothing ' uncomment this line if you are dragging out of old cell into new cell. Leave commented if you are dragging a copy
        oldrow = .Row
        oldcol = .Col
        .Row = .MouseRow
        .Col = .MouseCol
        Set .CellPicture = Picture1.Picture
        .Row = oldrow
        .Col = oldcol
    End With
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Picture1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.MouseCol)
    Picture1.Height = MSFlexGrid1.RowHeight(MSFlexGrid1.MouseRow)
    If Not MSFlexGrid1.Picture Is Nothing Then Set Picture1.Picture = MSFlexGrid1.CellPicture  ' ImageList1.ListImages(1).ExtractIcon
    Picture1.Drag
End Sub


User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by sal21 »

SpeakEasy wrote:
24 Sep 2021, 17:18
This example (non-production code,) needs a form with an MSFlexgrid and a picturebox (which you can set .Visible=False)

Code: Select all

Option Explicit

' Assumes msflexgrid has at least 4 rows
Private Sub Form_Load()
    With MSFlexGrid1
    .RowHeight(1) = 800
    .RowHeight(2) = 800
    .RowHeight(3) = 800
        .Row = 1
        .Col = 1
        .Text = "Example"
    Set MSFlexGrid1.CellPicture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\beany.bmp") ' You might want a different imnage, perhaps from an ImageList
    End With
End Sub

Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
    Dim oldrow As Long
    Dim oldcol As Long
    
    With MSFlexGrid1
        Set .CellPicture = Nothing ' uncomment this line if you are dragging out of old cell into new cell. Leave commented if you are dragging a copy
        oldrow = .Row
        oldcol = .Col
        .Row = .MouseRow
        .Col = .MouseCol
        Set .CellPicture = Picture1.Picture
        .Row = oldrow
        .Col = oldcol
    End With
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Picture1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.MouseCol)
    Picture1.Height = MSFlexGrid1.RowHeight(MSFlexGrid1.MouseRow)
    If Not MSFlexGrid1.Picture Is Nothing Then Set Picture1.Picture = MSFlexGrid1.CellPicture  ' ImageList1.ListImages(1).ExtractIcon
    Picture1.Drag
End Sub

tks, for code
but i just have the picture in cell of msflexgrid.
see the image.
in effect i need to drag the ombrella picture in circle in 1-6, and paste in the blank circle in 3-23, delete picture from initial position.
You do not have the required permissions to view the files attached to this post.

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by SpeakEasy »

My coder is a self-contained example. But it contains everything you need to achieve what you have asked for.

All; you need to do is delete/comment out/ignore the Form_Load event (and add the hidden picturebox)

Of course if you already have code in the MouseDown event you'll have to be careful how you pull in my MouseDown code, which triggers the whole drag drop stuff

Worries me that you can't see how the example can be very simply modified modified to work in your situation!

>i need to drag the ombrella picture in circle in 1-6, and paste in the blank circle in 3-23, delete picture from initial position.

I even include a comment in my code that explains this (or at least explains the specific changes you need to make to switch between duplicating the original image, and moving it - by imply commenting in or out a single line of code. in the example)

The example specifically answers your original post: "MSFLEXGRID drag the picture from a cell, and realese i a new cell?"

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by HansV »

Does this code, based on that by SpeakEasy, work for you, Sal? I cannot test it myself.

Code: Select all

Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
    Dim oldrow As Long
    Dim oldcol As Long
    
    With MSFlexGrid1
        Set .CellPicture = Nothing
        oldrow = .Row
        oldcol = .Col
        .Row = .MouseRow
        .Col = .MouseCol
        Set .CellPicture = ImageList1.ListImages(1)
        .Row = oldrow
        .Col = oldcol
    End With
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Picture1.Drag
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by sal21 »

HansV wrote:
25 Sep 2021, 18:47
Does this code, based on that by SpeakEasy, work for you, Sal? I cannot test it myself.

Code: Select all

Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
    Dim oldrow As Long
    Dim oldcol As Long
    
    With MSFlexGrid1
        Set .CellPicture = Nothing
        oldrow = .Row
        oldcol = .Col
        .Row = .MouseRow
        .Col = .MouseCol
        Set .CellPicture = ImageList1.ListImages(1)
        .Row = oldrow
        .Col = oldcol
    End With
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Picture1.Drag
End Sub
ERROR... see image
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by HansV »

Ah, that's why SpeakEasy used a PictureBox control. Please insert a PictureBox control PictureBox1, set its Visible property to False and use SpeakEasy's DragDrop and MouseDown code.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by SpeakEasy »

Yep, the PictureBox is really quite important here :smile:

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by HansV »

:thumbup:
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by sal21 »

SpeakEasy wrote:
25 Sep 2021, 21:57
Yep, the PictureBox is really quite important here :smile:
ok now the code work.
but i dont see the image attached to the cursor, during the drag...

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?

Post by SpeakEasy »

>Image attached

That wasn't in your original requirements ... :wink:

A quick (but nor perfect) solution would be to modify my MouseDown event to the following. You would need to addd another ImageList to your form (in my example's case ImageList2). This is used to provide the necessary Icon image rather than a Picture

Code: Select all

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)


        Picture1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.MouseCol)
        Picture1.Height = MSFlexGrid1.RowHeight(MSFlexGrid1.MouseRow)
        If MSFlexGrid1.CellPicture Then ' CellPicture rather than Picture in order to correct minor bug in previous version  
            ImageList2.ListImages.Clear
            ImageList2.BackColor = vbWhite
            ImageList2.ImageHeight = 32
            ImageList2.ImageWidth = 32  
            ImageList2.ListImages.Add 1, , MSFlexGrid1.CellPicture
            Set Picture1.DragIcon = ImageList2.ListImages(1).ExtractIcon ' DragIcon requires an icon not a picture. Without extra trickery, this is always a 32 x32 icon
            Set Picture1.Picture = MSFlexGrid1.CellPicture
        End If
        Picture1.Drag
End Sub