• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 608
  • Last Modified:

populating a label based on flex grid data using mouseover event

I have a flexgrid that I build with user data. If there is some user data in a cell, which I use the textmatrix and row and col to determine, I would like to display a label with some more user data if the cell isn't blank.

How can I display a label using the mouseover event if there is text in a cell and hide if there isn't.

Also, how can I position the label control based on where I am on the screen so the label control is close to the cell?

A snippet of code would be terrific.

Thanks!
0
samic400
Asked:
samic400
  • 3
  • 2
1 Solution
 
PaulHewsCommented:
This code shows how to populate a label from the mousemove event.  However, I don't move the label, as a label cannot appear in front of the grid (label is a windowless control.)  I also show how to use the tooltip of the flexgrid if you wish to use that instead of a label, as that moves where the mouse goes.  You can see when the tooltip is empty, it doesn't show up.
Option Explicit
 
Private Sub Form_Load()
    Dim i As Integer
    MSFlexGrid1.Rows = 0
    MSFlexGrid1.Cols = 3
    For i = 1 To 10
        If i <> 5 Then
            MSFlexGrid1.AddItem "Test" & vbTab & i & vbTab & "Test"
        Else
            MSFlexGrid1.AddItem "" & vbTab & i & vbTab & ""
        End If
    Next
End Sub
 
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    With MSFlexGrid1
    .ToolTipText = .TextMatrix(.MouseRow, .MouseCol)
    Label1.Caption = .TextMatrix(.MouseRow, .MouseCol)
    End With
End Sub

Open in new window

0
 
samic400Author Commented:
Almost exactly what I was looking for. I really need to pop up something, that is multi-lined, which rules out the tool tip. Perhaps a borderless form with a label in it. I need to present additional data to my customers that I don't want to cram in the flex grid cell. Could I do this and would this work?
0
 
samic400Author Commented:
My other concern is what if this form is already loaded, how would I check for that and repopulate it, and how can I position it on my screen so it isn't always in the middle (center) but maybe 10 px to the left of the grid I just moused over.
0
 
PaulHewsCommented:
I wouldn't bother with a new form.  Just add a picturebox, set backcolor = tooltip, autoredraw = true and visible = false
Option Explicit
 
Private Sub Form_Load()
    Dim i As Integer
    MSFlexGrid1.Rows = 0
    MSFlexGrid1.Cols = 3
    For i = 1 To 10
        If i <> 5 Then
            MSFlexGrid1.AddItem "Test" & vbCrLf & "test" & vbTab & i & vbTab & "Test"
        Else
            MSFlexGrid1.AddItem "" & vbTab & i & vbTab & ""
        End If
    Next
    picTip.Visible = False
    picTip.AutoRedraw = True
    
End Sub
 
 
 
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim strTip As String
    With MSFlexGrid1
    
    strTip = .TextMatrix(.MouseRow, .MouseCol)
    If Len(strTip) Then
        picTip.Cls
        picTip.Visible = True
        picTip.ZOrder
        picTip.Print strTip
        picTip.Move x + .Left + 60, y + .Top + 450, picTip.TextWidth(strTip) + 60, picTip.TextHeight(strTip) + 60
    Else
        picTip.Visible = False
    End If
    End With
End Sub

Open in new window

0
 
samic400Author Commented:
Thank you very much for your quick response.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now