My form has a SplitContainer with a TreeView in the top panel and a DataGridView in the bottom panel. The user selects a tree item and the item's data is displayed in the grid. The user can update the grid as needed and then click the Apply or Cancel button. All is well if the user clicks Apply or Cancel before selecting another tree item.
If the user is updating the grid and selects another tree item, I need to display a "Save Updates?" message with Yes and No buttons. If the user clicks Yes, I want to save the updates and then display the newly selected item's data.
The BeforeSelect event seemed like the best place to handle this situation, so that's what I did. The event fires as expected, but the message box seems to disrupt the event party. When the message box is dismissed, the BeforeSelect event is fired again and again. I also tried the AfterSelect event, but had the same results. I saw this same issue while googling, but no solution was offered.
I have displayed message boxes in event handlers before and don't remember having a problem. When I looked on the learn.microsoft.com site, their example for BeforeSelect has a message box. I'm guessing their example may not work.
Any ideas would be appreciated.
If the user is updating the grid and selects another tree item, I need to display a "Save Updates?" message with Yes and No buttons. If the user clicks Yes, I want to save the updates and then display the newly selected item's data.
The BeforeSelect event seemed like the best place to handle this situation, so that's what I did. The event fires as expected, but the message box seems to disrupt the event party. When the message box is dismissed, the BeforeSelect event is fired again and again. I also tried the AfterSelect event, but had the same results. I saw this same issue while googling, but no solution was offered.
I have displayed message boxes in event handlers before and don't remember having a problem. When I looked on the learn.microsoft.com site, their example for BeforeSelect has a message box. I'm guessing their example may not work.
Any ideas would be appreciated.