Results 1 to 4 of 4

Thread: [RESOLVED] Listview - Get last added value

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    England
    Posts
    135

    Resolved [RESOLVED] Listview - Get last added value

    Hi,

    I have a listview on a form and a textbox. When I enter text in the textbox and hit return it adds it to the listview - no problems so far.

    I'm not trying to stop duplicates by checking the last row in the listview and if it's the same as the textbox then disregard it.

    VB Code:
    1. If serials.ListItems.Item(serials.ListItems.Count).Text <> serialindiv.Text Then
    2.       serials.ListItems.Add , , serialindiv.Text
    3.    Else
    4.    End If

    That's the code I am using now, and I've tried a few variations on it, but still cant get it to work.

    Any help would be much appreciated.
    Cheers,
    Sparky.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listview - Get last added value

    Quote Originally Posted by Sparky
    I'm not trying to stop duplicates by checking the last row in the listview and if it's the same as the textbox then disregard it.
    I'm guessing that what you mean is that you ARE trying to stop duplicates so give this a go.

    Assuming serials is declared as a ListItem
    VB Code:
    1. Set serials = ListViewName.FindItem(txtTextBoxName.Text, , , lvwPartial)
    2.    
    3.    If Not serials Is Nothing Then
    4.      'go ahead and add it
    5.    Else
    6.     'maybe display a message box or something
    7.    End If

  3. #3
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: Listview - Get last added value

    Sparky, what you've posted looks right. Although it may be that the comparison is case-sensitive. Another approach you might take is to also use the text as the key into the listitem. The control won't allow duplicate keys, so any attempt to do so will result in an error being raised (which you could simply ignore).

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    England
    Posts
    135

    Re: Listview - Get last added value

    Cheers Hack!

    That worked perfectly. Thanks for your reply, I didnt notice it until today but that's working great.

    Thanks,
    Sparky.

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