Community discussion forum

how to remove the datas automatically in listbox?

Tags: .net India
  • 1 year ago
    hai all, i am using .net 2005.i do my project in vb.net windows application.i have 2 listbox named as connolistbox and lotnolistbox. i displayed the lotnos datas automatically in lotnolistbox based on i selected conno in connolistbox. i want to do like, if i removed all lotnos from lotnolistbox means that selected conno from connolistbox must be automatically removed. for example, i click 'conno101' in connolistbox means the 4 datas are lotno1,lotno2,lotno3,lotno4 are automatically displayed in lotnolistbox. then i remove 4 datas are lotno1,lotno2,lotno3,lotno4. now lotnolistbox is clear.when lotnolistbox clear means the 'conno101' must be automatically removed from connolistbox. if lotnolistbox not clear means the 'conno101' must be there in connolistbox.
  • 1 year ago

    Hello,

    You can make use of the SelectedIndexChanged() event of the lotnolistbox to implement the same. In the mentioned event,
    you can check if you have any items currently in the Lotnolistbox. In case the number of items is 0,then you can remove
    the selected Item from the connolistbox.

    For ex:

    Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged

     If Me.ListBox2.Items.Count = 0 Then

      Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)

     End If

    End Sub

    In the above code snippet, ListBox2 represents the lotnolistbox and ListBox1 is your connolistbox. Try the above
    code with the required changes and I believe this should work for you.

    Regards,

    Allen

    Allen Smith
    ComponentOne LLC

    www.componentone.com

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!