My Devexpress Gridview Delete event is firing multiple times
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 h开发者_StackOverflowad 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.
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.
精彩评论