get tag value from msflexgrid

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

get tag value from msflexgrid

Post by sal21 »

Possible to get .tag value, if is present in a cell, with MSFlexGrid1_MouseMove event?

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

Re: get tag value from msflexgrid

Post by HansV »

As far as I know, the Tag property applies to the MSFlexGrid control as a whole, not to individual cells.
Best wishes,
Hans

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

Re: get tag value from msflexgrid

Post by sal21 »

haaaa...
but i need to store on individual cell of msflexgrid a value, but hided in cell... other way?

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

Re: get tag value from msflexgrid

Post by HansV »

You could create an array (for example: GridArray) with the same number of rows and columns as the MSFlexGrid control, and store the values in the array.
The value for the cell you move the mouse over is GridArray(MSFlexGrid1.MouseRow, MSFlexGrid1.MouseCol)
Best wishes,
Hans

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

Re: get tag value from msflexgrid

Post by sal21 »

HansV wrote:
31 Aug 2021, 13:02
You could create an array (for example: GridArray) with the same number of rows and columns as the MSFlexGrid control, and store the values in the array.
The value for the cell you move the mouse over is GridArray(MSFlexGrid1.MouseRow, MSFlexGrid1.MouseCol)
hummmm...

tks for susggestion, but very complex for me.
my grid have 50 row and 50 column.

actually the code i have is :

Code: Select all

Private Sub MSFlexGrid1_Click()

    Dim LASTCOL As Integer

    LASTCOL = 51

    With Me.MSFlexGrid1

        COLONNA = .Col
        RIGA = .Row

        If .CellPicture = 0 And RIGA > 0 And COLONNA > 0 And COLONNA < LASTCOL Then

            '.TextMatrix(RIGA, COLONNA) = "0"
            '.CellAlignment = flexAlignLeftCenter
            'Set .CellPicture = LoadPicture(App.Path & "\IMG\" & "T.jpg")
            Set .CellPicture = Me.ImageList1.ListImages(1).Picture
            .CellPictureAlignment = flexAlignCenterCenter
            'Set .CellPicture = LoadPicture(App.Path & "\IMG\" & "OMBRELLONE_ROSSO.jpg")
            '.CellAlignment = flexAlignCenterCenter
            Me.LCOLONNA.Caption = COLONNA
            Me.LRIGA.Caption = RIGA
            
            ' .Tag = ""
           ' .Tag = COLONNA & "-" & RIGA

[b]i think the arry code go here?[/b]

        Else
            '.TextMatrix(RIGA, COLONNA) = ""
            'Set .CellPicture = Nothing
            '.TextMatrix(RIGA, COLONNA) = ""
            Set .CellPicture = LoadPicture("")
            
            'think
           [b] 'here the code to delete element in array[/b]
            
           ' .Tag = ""
            'Stop

        End If

    End With

    Me.Text1.SetFocus

End Sub
You do not have the required permissions to view the files attached to this post.

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

Re: get tag value from msflexgrid

Post by HansV »

I don't know what you want to do with the array...
Best wishes,
Hans

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

Re: get tag value from msflexgrid

Post by SpeakEasy »

>Private Sub MSFlexGrid1_Click()

But you asked about MouseMove. What is your MouseMove code?

And how were you (originally) intending to set the tags that you want to retrieve?

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

Re: get tag value from msflexgrid

Post by sal21 »

HansV wrote:
31 Aug 2021, 14:36
I don't know what you want to do with the array...
when i click on cell, the code save icon/image in cell.
in this case i need to store in a related cell, a value in a current cell with image/icon.

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

Re: get tag value from msflexgrid

Post by HansV »

Do you want to store images in the array? :confused: :scratch:
Best wishes,
Hans

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

Re: get tag value from msflexgrid

Post by SpeakEasy »

Here's a minimalist example, which assumes you want the 'tags' to be text. It also assumes you have a form with an MSFlexGrid control called MSFlexGrid2, and a command button called Command2. You'll need to populate the Grid by clicking the button before you try clicking on any random cell. It demonstrates a method, but is NOT production level code.

Code: Select all

Option Explicit
Private ShadowGrid() As String

Private Sub Command2_Click()
    PopulateGrid MSFlexGrid2
End Sub

Public Sub PopulateGrid(myGrid As MSFlexGrid)
    Dim myRow As Long
    Dim myCol As Long
    
    With myGrid
        ReDim ShadowGrid(1 To .Cols - 1, 1 To .Rows - 1)
        For myRow = 1 To .Rows - 1
            For myCol = 1 To .Cols - 1
                .Row = myRow
                .Col = myCol
                .Text = "Hello" & myCol * myRow
                ShadowGrid(myCol, myRow) = "Tag: Cell " & myCol & ", " & myRow
            Next
        Next
    End With
End Sub

Private Sub MSFlexGrid2_Click()
    With MSFlexGrid2
        If .MouseRow > 0 And .MouseCol > 0 Then
            Debug.Print ShadowGrid(.MouseCol, .MouseRow)
            ' or, since .Col and .Row are (mostly) the same as .MouseCol and .MouseRow in the msflexgrid's click event
            Debug.Print ShadowGrid(.Col, .Row)
        End If
    End With
End Sub