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:

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

Gavin-
  • Blind Luck
Status: Offline
Joined: Nov 02, 201310Year Member
Posts: 4,340
Reputation Power: 1865
Status: Offline
Joined: Nov 02, 201310Year Member
Posts: 4,340
Reputation Power: 1865
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
  • V5 Launch
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
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.