开发者

C#/WinForm: Force DataGrid not to add duplicate entry in a row

Is there are a way to 'validate' the contents of my data grid in windows form whether it is a duplicate copy or not?

I have a combo box inside my data grid and what I want to do is every time I add a new row, the user selects an item from the combo box. The next time the user adds a new row with the same entry from the previous ones (duplicate), it will not be added to the row.

I was thinking of removing or disabling the item from the combo box (datasource from the database) upon adding to the new row, so the user will not be able to duplicate the record.

What would be the best approach on this problem? Comm开发者_StackOverflowents and suggestions are welcome. Thank you.


You are planning to do the right thing. Removing the item from the combo is not a bad idea. Or else you can do a validation at the time of adding a new row to check if the item is already there in the grid.


Since the data source for your combo box is from a database why don't you just modify the query not to include items that are in the rows of your table, something like

SELECT item FROM itemList WHERE item not in (SELECT item FROM userAddedRow)


Instead of Going to Database u can perform your check operation in your Dataset. Perform Check operation From Dataset and if not Exist then send the Insert statement to the DataBase.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜