0
votes

I have to make a listbox with a few(8) names in it & double clicking on a name in the listbox will removed the name from it.

I have already add the names into the form using the listbox.items.add method & would display the names in it.

Then I enter the coding for 8 names in double_click procedure(listbox) using the "listbox.items.remove" method. However, when i try double clicking on a name in the listbox, it would remove all the names instead. What coding do i need? help appreciated!

2

2 Answers

1
votes
Option Strict On
Option Explicit On

Public Class Form1

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ListBox1.Items.Clear()
    ListBox1.Items.Add("1")
    ListBox1.Items.Add("2")
    ListBox1.Items.Add("3")
    ListBox1.Items.Add("4")
    ListBox1.Items.Add("5")
    ListBox1.Items.Add("6")
    ListBox1.Items.Add("7")
    ListBox1.Items.Add("8")
  End Sub

  Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    Dim i As Integer = ListBox1.SelectedIndex
    If i >= 0 And i < ListBox1.Items.Count Then
      ListBox1.Items.RemoveAt(i)
    End If
  End Sub

End Class
-1
votes

if you are looking at dynamic deletion of items, i think you should check out Jquery,Ajax,DOM there are a couple of nice tutorials that would help you with that. i just came across this one and found it interesting http://www.satya-weblog.com/2010/02/add-input-fields-dynamically-to-form-using-javascript.html