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?


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 & "';"
        Dim mySqlDataReader As String = CType(mySqlCommand.ExecuteScalar(), String)
        Return mySqlDataReader
    End Function

Edited 6 Years Ago by madlan: n/a

Attachments meh.JPG 17.33 KB

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, "")
                Me.ToolTip2.SetToolTip(Me.ListView2, Me.ListView2.GetItemAt(e.X, e.Y).Text)
            End If
        End If
    End Sub
This article has been dead for over six months. Start a new discussion instead.