Hi,

I'm trying to populate a tooltip with a list of users connected to a database when hovering over an row in a ListView.

I'm using sysprocesses to show a list of databases and the connections, how do I tie this together?

select loginame, hostname, blocked, db_name(dbid) from master..sysprocesses where db_name(dbid

I've attached a mock-up image of what I'm trying to achieve, is this possible?

Thanks.

Private Sub LVDatabases_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LVDatabases.ItemMouseHover
        ToolTip1.SetToolTip(CurrentDatabaseUsers(SQLServerName, Instance, LVDatabases.HoverSelection(0).Text))
    End Sub


Function CurrentDatabaseUsers(ByVal Server As String, ByVal Instance As String, ByVal Database As String)

        Dim mySqlConnection As New SqlConnection("server=" + Server + "\" + Instance + ";uid=sa;pwd=pwd;database=" + Database)
        Dim mySqlCommand As SqlCommand = mySqlConnection.CreateCommand()
        mySqlCommand.CommandText = "select loginame, hostname, blocked, db_name(dbid) from master..sysprocesses where db_name(dbid) = '" & Database & "';"
        mySqlConnection.Open()
        Dim mySqlDataReader As String = CType(mySqlCommand.ExecuteScalar(), String)
        mySqlConnection.Close()
        Return mySqlDataReader
    End Function

I've created the following which displays the text from the first column:

Private m_HoveredItem As ListViewItem
    Private Sub ListView2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseMove
        Dim lvi As ListViewItem = Me.ListView2.GetItemAt(e.X, e.Y)
        If Not lvi Is m_HoveredItem Then
            m_HoveredItem = lvi
            If lvi Is Nothing Then
                Me.ToolTip2.SetToolTip(Me.ListView2, "")
            Else
                Me.ToolTip2.SetToolTip(Me.ListView2, Me.ListView2.GetItemAt(e.X, e.Y).Text)
            End If
        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.