CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Deleting strings from listbox

    For example if I have SMTP_HOST twice in listbox, how can i eliminate on of them so basically i need to remove all double entries in my listbox leaving only those that are different

    Thank You


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Deleting strings from listbox

    try this code. It makes all entries unique

    private Sub Command1_Click()
    List1.AddItem "test"
    List1.AddItem "test"
    List1.AddItem "test"
    List1.AddItem "second"
    List1.AddItem "second"
    List1.AddItem "second"
    List1.AddItem "second"
    List1.AddItem "second"
    List1.AddItem "third"
    List1.AddItem "third"
    End Sub

    Sub makeUnique(l as ListBox)
    Dim i as Integer
    for i = l.ListCount - 1 to 0 step -1
    If l.List(i) = l.List(i - 1) then
    l.RemoveItem i
    End If
    next i
    End Sub





  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: Deleting strings from listbox

    ...sample assumes "Sorted = True" for the listbox...


  4. #4
    Join Date
    Jan 2000
    Posts
    72

    Re: Deleting strings from listbox

    isnt it even better if sorted=false?


  5. #5
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Deleting strings from listbox

    If I set sorted = false then it won't give me a right solution, I need to have it set to True.


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

Featured