tags:

views:

60

answers:

1

I've got a ToolTip showing when hovering over a row in my DataGridView - Works great except for the ToolTip flickering when over a row that displays it.

Private Sub DataGridView1_MouseHover(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
    Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X, e.Y)

    If hit.Type = DataGridViewHitTestType.Cell Then

        If Not hit Is m_HoveredItem Then
            Me.ToolTip2.Hide(Me.DataGridView1)
            m_HoveredItem = hit
            If hit Is Nothing Then
                Me.ToolTip2.SetToolTip(Me.DataGridView1, "")
            Else
                'Me.ToolTip2.SetToolTip(Me.DataGridView1, ConnectedUsers(Me.DataGridView1.Rows(hit.RowIndex).Cells("Database").Value, Instance))
                Me.ToolTip2.Show(ConnectedUsers(Me.DataGridView1.Rows(hit.RowIndex).Cells("Database").Value, Instance), DataGridView1, e.X, e.Y)
            End If
        End If

    End If

End Sub

I used a similar method for a ListView which worked great:

Private m_HoveredItem As ListViewItem
Private Sub lv_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

Dim lvi As ListViewItem = Me.LVDatabases.GetItemAt(e.X, e.Y)

If Not lvi Is m_HoveredItem Then
    Me.ToolTip2.Hide(Me.LVDatabases)
    m_HoveredItem = lvi
    If lvi Is Nothing Then
        Me.ToolTip2.SetToolTip(Me.LVDatabases, "")
    Else
        Me.ToolTip2.SetToolTip(Me.LVDatabases, ConnectedUsers(Me.LVDatabases.GetItemAt(e.X, e.Y).Text, Instance))
    End If
End If
End Sub
A: 
Private cellColumnIndex As Integer = -1, cellRowIndex As Integer = -1
Private Sub testDataGridView_CellMouseMove(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseMove
    If e.ColumnIndex <> Me.cellColumnIndex OrElse e.RowIndex <> Me.cellRowIndex Then
        Me.ToolTip2.Hide(Me.DataGridView1)
        Me.cellColumnIndex = e.ColumnIndex
        Me.cellRowIndex = e.RowIndex
        If Me.cellColumnIndex >= 0 AndAlso Me.cellRowIndex >= 0 Then
            Me.ToolTip2.SetToolTip(Me.DataGridView1, ConnectedUsers(Me.DataGridView1.Rows(e.RowIndex).Cells("Database").Value, Instance))
        End If
    End If
End Sub
madlan