Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I need to Maintain a unique list to maintain list of opened orders.

If I click on a row in datagridview an orderid is passed as a parameter to constructor.
Thus opening a new form. when I click on a row a new instance of a form open.

Now My question is that if I click a row five time five same orders opens.

I tried keeping a flag in the first line of the Cell click event but still I am getting multiple orders opened.

Now what I am trying is that I need a unique list type such as HashSet which support only unique values.

I will add the orderid to hashset. once it get another same orderid it produces exception thus it wont open multiple order. But the challenge for me is that I am using .NET 2.0 version.

So how to resolve this issue.
Help Appreciated.
Posted
Comments
Maciej Los 13-Feb-15 5:47am    
Have you tried to use Dictionary?
Rob Philpott 13-Feb-15 6:08am    
HashSet in .NET2.0? I thought it came in in 3.5.

Surely you can just check whether a collection .Contains() something before adding it, although this could be inefficient.
KUMAR619 13-Feb-15 9:14am    
Dictionary worked for me.
Thanks to Maciej Los

you can always check your object collection... like before opening a new instance you can check within the available list of opened forms and if you found one, activate it or bring it to front for work :)
 
Share this answer
 
I'd suggest to use Dictionary[^]. It works as you wish to work. Don't let you to enter the same value twice.

As Rob Philopott mentioned, you can use List[^] too, which provides functionality to check if value has been already added.

Finally, i'd suggest to check function/method which opens Order form.
 
Share this answer
 
Comments
KUMAR619 13-Feb-15 9:13am    
Dictionary worked for my scenario whereas List didn't work.
Thank you very much Maciej Los
Maciej Los 13-Feb-15 9:59am    
You're very welcome ;)
BillWoodruff 13-Feb-15 10:27am    
+5
Maciej Los 13-Feb-15 10:53am    
Thank you, Bill ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900