Results 1 to 7 of 7

Thread: [RESOLVED] Listbox Items Text Addition/Removal

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    166

    Resolved [RESOLVED] Listbox Items Text Addition/Removal

    Hello everyone.

    I'm trying add a certain feature to a listbox, where the this listbox holds several web bookmarks which are grouped by the bookmark names and when the user passes the mouse through each bookmark, listed in the listbox, the url of the current hovered bookmark will be displayed right after its name (pretty much like google chrome).

    Here's a picture to better describe:

    Name:  1.jpg
Views: 219
Size:  5.6 KB

    I have no clue on how I achieve this, because the listbox control doesn't offer the hittest procedure, which would be ideal for this case.
    Does anyone know a route for this achievement?
    Last edited by Simbiose; Dec 4th, 2014 at 09:11 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,394

    Re: Listbox Items Text Addition/Removal

    try this:

    Code:
    Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
        Dim index As Integer = ListBox1.IndexFromPoint(e.Location)
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    166

    Re: Listbox Items Text Addition/Removal

    Quote Originally Posted by .paul. View Post
    try this:

    Code:
    Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
        Dim index As Integer = ListBox1.IndexFromPoint(e.Location)
    End Sub
    Well, I tried to use the IndexFromPoint function, since I've read about it on a forum I can't recall right now.
    However, all that this function gives is the pixel of where the cursor is on the listbox at runtime, it doesn't tell you which item you're currently on

    I've tried to script some kind of if statement to compare the item the user is hovering with the index variable, but I can't follow the logic :/

    Any lights on how I could do that?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,394

    Re: Listbox Items Text Addition/Removal

    IndexFromPoint gives the list index of the item at e.Location (the mousepointer location inside the listbox in pixels)

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,394

    Re: Listbox Items Text Addition/Removal

    here's an example:

    Name:  04-12-2014 16.20.06.png
Views: 61
Size:  7.5 KB

    Code:
    Public Class Form1
    
        Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
            Dim index As Integer = ListBox1.IndexFromPoint(e.Location)
            If index <> -1 Then
                Label1.Text = String.Format("MousePointer is over: index:{0} item text:{1}", index, ListBox1.GetItemText(ListBox1.Items(index)))
            Else
                Label1.Text = "No item at point"
            End If
        End Sub
    
    End Class

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    166

    Re: Listbox Items Text Addition/Removal

    Quote Originally Posted by .paul. View Post
    here's an example:

    Name:  04-12-2014 16.20.06.png
Views: 61
Size:  7.5 KB

    Code:
    Public Class Form1
    
        Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
            Dim index As Integer = ListBox1.IndexFromPoint(e.Location)
            If index <> -1 Then
                Label1.Text = String.Format("MousePointer is over: index:{0} item text:{1}", index, ListBox1.GetItemText(ListBox1.Items(index)))
            Else
                Label1.Text = "No item at point"
            End If
        End Sub
    
    End Class
    Well... this one got me stumped O.o
    I just noticed I misread the description of the IndexFromPoint function, it's right there... saying what it does...
    *facekeyboard*

    Thanks for the help guys!

  7. #7
    New Member
    Join Date
    Feb 2015
    Posts
    10

    Re: [RESOLVED] Listbox Items Text Addition/Removal

    In my project, I have one listbox and it load its items from txt file. I insert a timer in the form to update the item in the listbox : if user adds new line in the text file, this line is added automatically as new item. But my problem, when user delete a line in the listbox, how to delete automatically this item in the listbox ?
    Can someone help me ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width