Dynamically set method for tabPage
I have TabControl. I added it to tabpages. To one of them(tpTags) I dynami开发者_如何学Gocally add usercontrol tagsModule. When I'll click at tpTags I wanna to call method on tagsModule BindData
NEW CODE:
TabPage tpTags = new TabPage();
tabControl1.TabPages.Add(tpTags);
...setting properties...
TagsModule tagsModule = newTagsModule(_countryCode, ObjectType.Country);
tpTags.Select() = tpTags.BindData(); //**How do it ??**
tpTags.Controls.Add(tagsModule);
It could be: "how do I set an event that triggers when this tab is selected?"
You have to wire up the delegate to the event like this:
tabControl1.SelectedIndexChanged += new EventHandler(this.tabControl1_SelectedIndexChanged);
Now you can put all your code inside this method
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(TabControl1.SelectedTab == tpTags)
{
// BindData();
}
}
BindData() runs whenever your tabPage 'tpTags' is selected. If you want only for the first time, set a flag.
If you mean "how do I make this the current tab", then:
tabs.SelectedTab = tpTags;
If you mean "how do I respond when this tab is selected", then look at the tpTags.SelectedIndexChanged
event (you don't necessarily need to care about the index when handling this event - you can just check tabs.SelectedTab
again).
精彩评论