|
-
Apr 7th, 2006, 11:10 AM
#1
Thread Starter
Addicted Member
[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:
If serials.ListItems.Item(serials.ListItems.Count).Text <> serialindiv.Text Then
serials.ListItems.Add , , serialindiv.Text
Else
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.
-
Apr 7th, 2006, 11:16 AM
#2
Re: Listview - Get last added value
 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:
Set serials = ListViewName.FindItem(txtTextBoxName.Text, , , lvwPartial)
If Not serials Is Nothing Then
'go ahead and add it
Else
'maybe display a message box or something
End If
-
Apr 7th, 2006, 11:18 AM
#3
Hyperactive Member
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).
-
Apr 10th, 2006, 08:33 AM
#4
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|