views:

36

answers:

2

Suppose I have 2 tabs with parameters to be set and two buttons under them, one serves to Ok the procedure and do the math, the other clears the values entered by the user to their defaults.

What I'd like to do is to make the Clear button sensitive to whatever tab is currently active. So if I'm in Tab 1 and press "Clear", only the Tab 1 values are back to their defaults. Is there an easy way to do this?

I also realize having a clear button on each tab might be easier to do, but I don't think it'd look as good. Though I might consider this or just resetting all the values if there is no clean alternative.

A: 

Hi,

You can check which tab is currently selected by using the following command.

If DirectCast(DirectCast(YourtabCtrl, System.Windows.Forms.TabControl).SelectedTab,Sytemtem.Windows.Forms.TabPage).Name="Tab1" then 'Clear controls Else 'Clear Controls End if

Hope this is going to help.

Thanks, Jagdev josan

jagdev josan
A: 

Why don't you simply check which tab is currently selected from the code-behind?

I've uploaded a working example here.

But this should give you an overall idea

    private void bOK_Click(object sender, RoutedEventArgs e)
    {
        switch (tabControl1.SelectedIndex)
        {
            case 0: Tab0_OK(); break;
            case 1: Tab1_OK(); break;
        }
    }

    private void bClear_Click(object sender, RoutedEventArgs e)
    {
        switch (tabControl1.SelectedIndex)
        {
            case 0: Tab0_Clear(); break;
            case 1: Tab1_Clear(); break;
        }
    }

Regards,
Mihir Gokani

Mihir Gokani