Solved

How to remove a selected item in a listbox by double-click

Posted on 2004-10-31
277 Views
Last Modified: 2010-04-23
How can I remove a selected item in a list box by double-clicking?

If this requires a procedure please provide an example.

Thanks for your time
0
Question by:Stella Pauley
    2 Comments
     
    LVL 19

    Expert Comment

    by:Desp
    put this line in the Doubleclick Event of the Listbox:

    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    0
     
    LVL 85

    Accepted Solution

    by:
    The extra code in the MouseDown event will prevent the selected index from being deleted if you double click in the ListBox below the last item.  You also need to check if there is no selected item before attempting to delete it:

        Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
            ListBox1.SelectedIndex = ListBox1.IndexFromPoint(New Point(e.X, e.Y))
        End Sub

        Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
            If ListBox1.SelectedIndex <> -1 Then
                ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
            End If
        End Sub
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    860 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now