Search code examples
c#eventstabcontroltabpage

I need to access TabPage before removing TabControl


In main program I add TabPage (UserControl) to TabControl. This Control has few data I would like to have before removing it. When using TabControl.RemoveControl the sender is TabControl, and I cannot access the TabPage because I don't know which one is it (using TabControl.TabPages.Count I know that my Tab ain't remove yet so I can access it).

Is there any Event for TabControl to mark TabPage that is going to be removed? or any other idea.

Basically: I add tabpage with editing of some MySql data, and after closing i would like check is there was a Edit on that row (via bool wasEdited) and if it was edited i would like to read the id of that row. If the form for editing wasn't in seperate file i would just run method on that, and I can't use static method to access non static DataGridView to update row.


Solution

  • in event handler TabControl.ControlRemoved you have ControlEventArgs e. Control that's being removed is e.Control.