You are viewing our Forum Archives. To view or take place in current topics click here.

Code to not allow duplicates in a listbox csharp.Posted:

Gavin-
  • Ninja
Status: Offline
Joined: Nov 02, 20134 Year Member
Posts: 4,307
Reputation Power: 827
pretty much dont want duplicates going into the listbox from the datagridview when i click add to cart

[ Register or Signin to view external links. ]
#2. Posted:
speed
  • 2000 Thanks
Status: Offline
Joined: Jun 11, 20099 Year Member
Posts: 9,897
Reputation Power: 3150
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
I'm not going to feed you code because you're already making quite a few topics on this one program, but I can help you out with the logic. The rest can be googled fairly easily.

1. Get the value of the input you want to check against (title)
2. Get all listbox items (listboxitems)
3. Cycle through each listbox item (foreach item in listboxitems)
4. Check the listbox item against the input value (if title = item)
5. If no matches have been found, add the input to the listbox

Keep in mind you'll need to do the proper conversions to get the string value of the listbox item so that you can compare it to the input string.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.