MSFLEXGRID drag the picture from cell, and realese i a new cell?
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
MSFLEXGRID drag the picture from cell, and realese i a new cell?
MSFLEXGRID drag the picture from a cell, and realese i a new cell?
-
- Administrator
- Posts: 78586
- 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?
I'm sorry, i cannot help you with this.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
-
- 4StarLounger
- Posts: 563
- Joined: 27 Jun 2021, 10:46
Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?
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
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?
tks, for codeSpeakEasy wrote: ↑24 Sep 2021, 17:18This 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
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.
-
- 4StarLounger
- Posts: 563
- Joined: 27 Jun 2021, 10:46
Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?
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?"
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?"
-
- Administrator
- Posts: 78586
- 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?
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
Hans
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?
ERROR... see imageHansV wrote: ↑25 Sep 2021, 18:47Does 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
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78586
- 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?
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
Hans
-
- 4StarLounger
- Posts: 563
- Joined: 27 Jun 2021, 10:46
Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?
Yep, the PictureBox is really quite important here
-
- Administrator
- Posts: 78586
- 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?
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
-
- 4StarLounger
- Posts: 563
- Joined: 27 Jun 2021, 10:46
Re: MSFLEXGRID drag the picture from cell, and realese i a new cell?
>Image attached
That wasn't in your original requirements ...
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
That wasn't in your original requirements ...
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