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!
LVL 13
samic400Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
samic400Author Commented:
Thank you very much for your quick response.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.