Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Floating Textbox on Listview

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
Hi all,

I have done some work to create a floating textbox above a listview. It currently floats over the first column:

Code:
    Private Sub lst_PlayersAll_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lst_PlayersAll.MouseUp
        ' bont is the listbox
        Dim MyItem As ListViewItem = lst_PlayersAll.SelectedItems(0)
        If Not IsNothing(MyItem) Then
            Dim ClickedItem As Rectangle = MyItem.Bounds
            ClickedItem.X += Me.lst_PlayersAll.Left + GroupBox1.Left + 1
            ClickedItem.Y += Me.lst_PlayersAll.Top + GroupBox1.Top + 1
            bont.Height = MyItem.Bounds.Height
            ClickedItem.Width = lst_PlayersAll.Columns(0).Width
            bont.Bounds = ClickedItem
            bont.Text = MyItem.Text
            bont.Visible = True
            bont.BringToFront()
            bont.Focus()
        End If
    End Sub

    Private Sub bont_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles bont.KeyUp
        If e.KeyCode = Keys.Escape Then
            bont.Visible = False
        End If
    End Sub

This part seems pretty straight foward. What I can't seem to figure out is how to save the textbox changes. I have tried using various leave/focus options of the listview; however, since the textbox itself has the focus, the listview's options don't seem to work.

I guess I have some questions:

1) Would I be able to use the listview's leave/focus options if I used the setparent option, to change the parent of the textbox from the form, to the listview? - I just thought of this.

2) Is there another way?
 
OK All, I have an ammended code for this:

Code:
' At Top
    Private SelectedPlayer As ListViewItem
    Private PrevSelectedPlayer As ListViewItem



    Private Sub lst_PlayersAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst_PlayersAll.Click
        If Not IsNothing(Me.lst_PlayersAll.SelectedItems(0)) Then
            PrevSelectedPlayer = SelectedPlayer
            SelectedPlayer = Me.lst_PlayersAll.SelectedItems(0)
        End If
        If bont.Visible Then
            Dim iIDX As Integer = -999
            If Not IsNothing(PrevSelectedPlayer) Then
                iIDX = PrevSelectedPlayer.Index
            End If
            If SelectedPlayer.Index <> iIDX Then
                PrevSelectedPlayer.Text = bont.Text.Trim
                bont.Visible = False
            End If
        End If
    End Sub

    Private Sub lst_PlayersAll_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst_PlayersAll.DoubleClick
        Dim iIDX As Integer = -999
        If Not IsNothing(PrevSelectedPlayer) Then
            iIDX = PrevSelectedPlayer.Index
        End If
        If SelectedPlayer.Index <> iIDX Then
            Dim MyItem As ListViewItem = lst_PlayersAll.SelectedItems(0)
            If Not IsNothing(MyItem) Then
                Dim ClickedItem As Rectangle = MyItem.Bounds
                bont.Height = MyItem.Bounds.Height
                ClickedItem.Width = lst_PlayersAll.Columns(0).Width
                bont.Bounds = ClickedItem
                bont.Text = MyItem.Text
                bont.Visible = True
                bont.BringToFront()
                bont.Focus()
            End If
        Else
            If bont.Visible Then
                bont.Focus()
            End If
        End If
    End Sub

This does quite well, I think. Does anyone forsee any problems with this technique?

Also, I have not tested, but if I apply some sort of sorting after each change of the first column, will this effect my outcome?

Maybe not if I keep my PrevSelectedPlayer reference up to date while doing so?

Does anyone know of any free controls that could do this same thing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top