Results 1 to 2 of 2

Thread: [SOLVED] Specific counting in listbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    [SOLVED] Specific counting in listbox

    Hey,
    I'm having a problem and I can't seem to crack it.
    Let's say these items are in a listbox

    name-05.06.2010
    somtext-05.06.2010
    lol-06.06.2010
    sth-06.06.2010
    hello-06.06.2010
    Each of the items has the date it was added on the back after the -
    Now I select sth-06.06.2010
    This is the second item of 06.06.2010
    How would I get "2" in a label, as it's the second item of that date?

    If I'd chose hello-06.06.2010 then 3 would appear
    If I'd chose somtext-05.06.2010 then 2 would appear.

    How would I count the index of it based on the date?
    Last edited by vixez; Jun 6th, 2010 at 12:19 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: Specific counting in listbox

    Okay, sorted it out

    Code:
     'Getting all names with 06.06.2010 as date      
     For Each item In lstMails.Items
                If item.ToString.Contains("06.06.2010") Then
    'add them to a different listbox
                    lstSortToSelected.Items.Add(item)
                End If
            Next
    
            Dim itemstring As String
            Dim index As Integer
    
            For Each item In lstSortToSelected.Items
    'if item has the same name as the selected one in lstMails, then remember the name
                If item.ToString.Contains(lstMails.SelectedItem) Then
                    itemstring = item
                End If
            Next
    'select the item that was remembered
            lstSortToSelected.SelectedItem = itemstring
    'get the selected index
            index = lstSortToSelected.SelectedIndex
    Done!

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