add ico in msflexgrid

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

add ico in msflexgrid

Post by sal21 »

I just have a msflexgrid filled.

now, when i click on a cell, for example on: ABBAZIA, i need to insert before ABBAZIA an icon (c:\icon\flip.ico)
if i click on a other cell, for example: BERGOGNA, i need to add before BERGOGNA an icon (c:\icon\flip.ico), and delete the last icon added to ABBAZIA ecc ...

i hope you understand me.

note:
only for the value in comun 8
You do not have the required permissions to view the files attached to this post.

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

Re: add ico in msflexgrid

Post by HansV »

I cannot test this, so there may be a better way. Create a blank icon in the same folder named Blank.ico

Code: Select all

Private Sub MSFlexGrid1_Click()
    Static OldRow As Long
    Dim NewRow As Long
    With Me.MSFlexGrid1
        If .Col = 8 And .Row <> OldRow Then
            NewRow = .Row
            .Row = OldRow
            .CellPicture = LoadPicture("c:\icon\blank.ico")
            .Row = NewRow
            .CellPicture = LoadPicture("c:\icon\flip.ico")
            OldRow = NewRow
        End If
    End With
End Sub
Best wishes,
Hans

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

Re: add ico in msflexgrid

Post by sal21 »

HansV wrote:
28 Oct 2023, 10:58
I cannot test this, so there may be a better way. Create a blank icon in the same folder named Blank.ico

Code: Select all

Private Sub MSFlexGrid1_Click()
    Static OldRow As Long
    Dim NewRow As Long
    With Me.MSFlexGrid1
        If .Col = 8 And .Row <> OldRow Then
            NewRow = .Row
            .Row = OldRow
            .CellPicture = LoadPicture("c:\icon\blank.ico")
            .Row = NewRow
            .CellPicture = LoadPicture("c:\icon\flip.ico")
            OldRow = NewRow
        End If
    End With
End Sub
.CellPicture = higlight for error!
invalid use of property....

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

Re: add ico in msflexgrid

Post by HansV »

I hope that someone who knows VB6 can help you.
Best wishes,
Hans

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

Re: add ico in msflexgrid

Post by sal21 »

HansV wrote:
28 Oct 2023, 11:36
I hope that someone who knows VB6 can help you.
Set .CellPicture = LoadPicture("c:\icon\flip.ico")

resolved, my self

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

Re: add ico in msflexgrid

Post by SpeakEasy »

<edit: ah, looks like our posts crossed)


You need Set

I'd slightly modify Han's code to:

Code: Select all

Private Sub MSFlexGrid1_Click()
    Static OldRow As Long
    Dim NewRow As Long
    With Me.MSFlexGrid1
        If .Col = 8 And .Row <> OldRow Then
            NewRow = .Row
            .Row = OldRow
            Set .CellPicture = Nothing ' Don't really need LoadPicture("c:\icon\blank.ico")
            .Row = NewRow
            Set .CellPicture = LoadPicture("c:\icon\flip.ico")
            OldRow = NewRow
        End If
    End With
End Sub
But bear in mind that in the msflexgrid control neither the icon or text in the cell know anything about each other, so you'll need to figure out a way to position the text appropriately when the icon is inserted. The simple alignment settings available for the pricture and/or the text alone may not be sufficient. Personally, I'd probably introduce an extra column just to display the icon.

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

Re: add ico in msflexgrid

Post by sal21 »

SpeakEasy wrote:
28 Oct 2023, 14:37
<edit: ah, looks like our posts crossed)


You need Set

I'd slightly modify Han's code to:

Code: Select all

Private Sub MSFlexGrid1_Click()
    Static OldRow As Long
    Dim NewRow As Long
    With Me.MSFlexGrid1
        If .Col = 8 And .Row <> OldRow Then
            NewRow = .Row
            .Row = OldRow
            Set .CellPicture = Nothing ' Don't really need LoadPicture("c:\icon\blank.ico")
            .Row = NewRow
            Set .CellPicture = LoadPicture("c:\icon\flip.ico")
            OldRow = NewRow
        End If
    End With
End Sub
But bear in mind that in the msflexgrid control neither the icon or text in the cell know anything about each other, so you'll need to figure out a way to position the text appropriately when the icon is inserted. The simple alignment settings available for the pricture and/or the text alone may not be sufficient. Personally, I'd probably introduce an extra column just to display the icon.
GOOD idea to add new column!