HelloWorld
HelloWorld

Reputation: 1091

TabControl Saving on selected tab item changed

I need to save data in distinct TabItem every time when user switches to another tabitem.

I try to operate TabControl.SelectionChanged event, but there is no info about previously selected tab item.

So, how to get moment when user switches from my TabItem to another?

Upvotes: 1

Views: 2127

Answers (4)

mafu
mafu

Reputation: 32710

What you need exists in the parameter SelectionChangedEventArgs e:

  • e.AddedItems
  • e.RemovedItems

Upvotes: 0

WGF_Bean
WGF_Bean

Reputation: 31

Use the Enter and Leave events of the individual tabs. If you need the enter event to fire on code start up then you may need to programmatically change the selected tab to one that is different than at design time.

Upvotes: 3

kishhr
kishhr

Reputation: 191

Use the below code:

private object LastTab = null;

private void tabSelectionChanged(...)
{
  if(LastTab != null)
  {
     //Do save
  }

  LastTab = control.SelectedContent;
}

Here the the content will be of type object you can type cast to specific class and do the save operation

Upvotes: 0

Amen Ayach
Amen Ayach

Reputation: 4348

You can make a global variable to store what is the last tab

private TabPage LastTab = null;

private void tabSelectionChanged(...)
{
  if(LastTab != null)
     //Do save

  LastTab = tab.SelectedTabPage;// or equivalent 
}

Upvotes: 1

Related Questions