我的 Devexpress Gridview 删除事件多次触发

发布于 2024-09-10 19:04:44 字数 618 浏览 4 评论 0原文

我有一个 Devexpress Gridview,它链接到删除、获取和更新存储过程。我遇到的问题是,当我运行程序时,在网格中选择一行并按删除键会多次触发该事件。具体来说,它删除所选行,然后重新获取数据,以便焦点返回到第一行。这就是我想要的。不幸的是,它从我的列表的开头开始,然后逐行删除它所到达的每一行。删除行后,它会继续执行几次。我知道这一点是因为对于每个删除的行,它都会询问我是否要删除它。如果我说“否”,那么行似乎会消失,直到我在删除完成后手动刷新它。为了使其更加随机,在我手动刷新网格后,第二行总是会重新出现。

我看到大多数在互联网上遇到此问题的人都将事件与多个对象匹配,但我自己没有创建动作侦听器,设计器代码曾经这样做过,并且我已经按照我一贯的方式进行了设置。此外,我尝试对此进行调试(Visual Studio 2008),并且它不会在断点处停止,即使它打印出该行正下方的行。

编辑:

我已经缩小了问题范围。我之前没有提到,但我有一个树列表,显示部门及其员工的名称。单击某个部门时,它会在窗口的右侧窗格中显示上述网格。当程序第一次启动时,删除操作侦听器仅被触发一次。当我选择第二个部门时,在网格中选择一行,它会被触发两次。基本上每次我选择不同的部门时都会触发另一个删除操作。因此,如果我选择了另一个部门 5 次,那么当我尝试删除一行时,删除操作将被触发 5 次。

I have a Devexpress Gridview that is linked to a delete, fetch and update stored procedure. The problem I am having is that when I run my program, select a row in the grid and press delete it fires the event multiple times. Specifically it deletes the selected row and then I re-fetch the data so the focus returns to the first row. Which is what I want. Unfortunately it starts at the beginning of my list and goes down it row by row deleting each row it comes to. It then continues several more times after the rows are deleted. I know this because for each deleted row it asks me if I want to delete it. If I say no then the rows appear to disappear until I manually refresh it after the deleting is done. To make this even more random the second row always reappears after I manually refresh the grid.

I saw that most people who had this problem on the internet had the event matched to several objects yet I don't create the actionlistener myself the designer code did this once and I have set it up the same way I always do. In addition I tried to debug this (Visual Studio 2008) and it doesn't stop at the breakpoints even though it prints out the line directly below the line.

EDIT:

I have narrowed down the problem. I didn't mention before but I have a treelist that displays the names of departments and their employees. When a department is clicked it shows the grid mentioned above in the right pane of the window. When the program is first started the delete actionlistener is just fired once. When I select a second department a choose a row in the grid it is fired twice. Basically every time I select a different department there is another delete fired. So if I have selected another department 5 times then when I try to delete a row the delete is fired 5 times.

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

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

发布评论

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

评论(1

独木成林 2024-09-17 19:04:45

所以我找到了答案,希望它可以帮助别人。

基本上,我在单击某个部门时设置右窗格的同一函数中设置存储过程。因此,当我单击树列表上的某个部门时,它会再次设置网格。所以本质上它每次都在重新创建它。为了解决这个问题,我只是将网格的创建移至一开始的主函数中,该函数仅被调用一次。

So I found my answer and I hope it can help someone.

Basically I set the stored procedure within the same function that sets up my right pane when a department is clicked. So when I click on a department on the treelist it would set up the grid again. So essentially it was recreating it each time. To solve I just moved the creation of the grid and to the main function at the beginning that is only called once.

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