C#/WinForm:强制 DataGrid 不要在一行中添加重复条目

发布于 2024-10-01 02:08:00 字数 233 浏览 2 评论 0原文

有没有办法以 Windows 形式“验证”我的数据网格的内容,无论它是否是重复副本?

我的数据网格中有一个组合框,我想要做的是每次添加新行时,用户从组合框中选择一个项目。下次用户添加具有与先前条目相同的条目(重复)的新行时,它将不会添加到该行中。

我正在考虑在添加到新行时从组合框(数据库中的数据源)中删除或禁用该项目,因此用户将无法复制该记录。

解决这个问题的最佳方法是什么?欢迎提出意见和建议。谢谢。

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? Comments and suggestions are welcome. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞清仓 2024-10-08 02:08:00

你正计划做正确的事。从组合中删除该项目并不是一个坏主意。或者,您可以在添加新行时进行验证,以检查该项目是否已存在于网格中。

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.

客…行舟 2024-10-08 02:08:00

由于组合框的数据源来自数据库,为什么不修改查询以不包含表行中的项目,例如

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

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)
七分※倦醒 2024-10-08 02:08:00

您可以在数据集中执行检查操作,而不是转到数据库。
对 Dataset 执行 Check 操作,如果不存在则发送 Insert 语句
到数据库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文