Question about using SelectedTab
I am crea开发者_StackOverflow社区ting an app that uses tabs. I want to be able to add, edit, and delete on each tab. I have these three buttons outside of the tabs so they can be used for each one. I am trying to figure out how to use SelectedTab so that the tab I am currently on will be the one that gets changed. Any help is appreciated. thanks
You could do something like this in your buttons' event handlers:
if (tabControl1.SelectedTab == tabPage1)
{
/* do something */
}
else if (tabControl1.SelectedTab == tabPage2)
{
/* do something else */
}
You can get the currently selected tab by using TabControl.SelectedTab
property. Once you got the selected tab, you can make appropriate changes in selected tab.
For delete, put this in the event handler of the delete button:
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
For add, use this:
var newTabPage = new TabPage("Tab Name");
tabControl1.TabPages.Add(myTabPage);
Instead of using buttons, I let users double click on the datagrid and a new window where they can edit and such.
精彩评论