Click here to Skip to main content
15,921,636 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Dear,

i am entring data into datagrid from textbox i want to avoid duplicate entry into datagrid. any prompt help will be appreciated.

I am working in windows application.

Best Regards,

If possible, try to put some logic in your query or collection / datasource that holds this data - it might be easier.
Share this answer
[no name] 25-Apr-11 3:43am    
I 100% agreed, actually I do not prefer to implement any data manipulation logic from the GUI end.
Tarun.K.S 25-Apr-11 3:48am    
How about using HashSet?
Abhinav S 25-Apr-11 3:53am    
Could be done - but some care needs to be taken to ensure that keys dont duplicate right? At least the error handling should be proper.
Tarun.K.S 25-Apr-11 4:04am    
Yep true. But I was thinking that, if there are hundreds or lets say thousands of items, then looping through all and checking for duplicates can be expensive. But I guess that might be the only way to check.
Bind the datagrid with a data table and make the column as unique / primary key. This will create a constraint in the table which will prevent it from adding duplicate values

see sample code for unique key from msdn

DataTable custTable = custDS.Tables["Customers"];
UniqueConstraint custUnique = new UniqueConstraint(new DataColumn[]
Share this answer

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