How to detect when a tab page is being selected?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VmFuZXNzYQ==?=

    #1

    How to detect when a tab page is being selected?

    Hi all!

    I have a tab control and in one tab page I have 8 textbox and 2 grids. The
    textbox are all numerics and have the following behavior: when I digit the
    2nd textbox then the 3rd textbox is updated with the 2nd more the difference
    between the 1st and 2nd, and so on.

    Example 1:
    TB 1: 10, TB 2: 20 -TB 3 will be updated with 30
    Example 2:
    TB 1: 15, TB 2: 30, TB 3: 45 -TB 4 will be updated with 60

    When I say "will be updated", it is updated on textbox_Validat ing() event.

    If I'd like to digit just 4 textbox, I left the 5th with zero (or blank) and
    it works fine. If I am on the 4th textbox and then click on one of the grids,
    it is ok too. But if the focus is on the 4th textbox (with some value greater
    than 0), and I click on another page of the tab control, it is not working.
    The problem is that on textbox_Validat ing() event, where I have the following
    test:

    private void textbox_Validat ing(object sender, CancelEventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb.Focused == true)
    {
    UpdateNextTextb ox();
    }
    }

    In UpdateNextTextb ox() method I update the next number according I explained
    above and call Focus() event of the next textbox. When I click on the grid,
    the "if (tb.Focused == true)" is false and the next textbox will not be
    updated, and it is ok. The problem is that if I click on another tab page,
    this "if" is true, i.e., the focus is still on the textbox, and the next
    textbox is updated, what is wrong.

    I already tried Selecting(), Deselecting(), SelectedIndexCh anged() and other
    events of tab control, but all them are called after textbox_Validat ing(). So
    what I want is to know if it is changing tab page before
    textbox_Validat ing(). Any idea?

    Thank you!
    Vanessa
  • Stanimir Stoyanov

    #2
    Re: How to detect when a tab page is being selected?

    Hi Vanessa,

    Set the CausesValidatio n property of your TabControl to false. You don't
    have to handle its events either.

    Best Regards,
    Stanimir Stoyanov
    www.stoyanoff.info

    "Vanessa" <Vanessa@discus sions.microsoft .comwrote in message
    news:F79BB4E3-F826-429C-AAEA-5DE6D041E741@mi crosoft.com...
    Hi all!
    >
    I have a tab control and in one tab page I have 8 textbox and 2 grids. The
    textbox are all numerics and have the following behavior: when I digit the
    2nd textbox then the 3rd textbox is updated with the 2nd more the
    difference
    between the 1st and 2nd, and so on.
    >
    Example 1:
    TB 1: 10, TB 2: 20 -TB 3 will be updated with 30
    Example 2:
    TB 1: 15, TB 2: 30, TB 3: 45 -TB 4 will be updated with 60
    >
    When I say "will be updated", it is updated on textbox_Validat ing() event.
    >
    If I'd like to digit just 4 textbox, I left the 5th with zero (or blank)
    and
    it works fine. If I am on the 4th textbox and then click on one of the
    grids,
    it is ok too. But if the focus is on the 4th textbox (with some value
    greater
    than 0), and I click on another page of the tab control, it is not
    working.
    The problem is that on textbox_Validat ing() event, where I have the
    following
    test:
    >
    private void textbox_Validat ing(object sender, CancelEventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb.Focused == true)
    {
    UpdateNextTextb ox();
    }
    }
    >
    In UpdateNextTextb ox() method I update the next number according I
    explained
    above and call Focus() event of the next textbox. When I click on the
    grid,
    the "if (tb.Focused == true)" is false and the next textbox will not be
    updated, and it is ok. The problem is that if I click on another tab page,
    this "if" is true, i.e., the focus is still on the textbox, and the next
    textbox is updated, what is wrong.
    >
    I already tried Selecting(), Deselecting(), SelectedIndexCh anged() and
    other
    events of tab control, but all them are called after textbox_Validat ing().
    So
    what I want is to know if it is changing tab page before
    textbox_Validat ing(). Any idea?
    >
    Thank you!
    Vanessa

    Comment

    • =?Utf-8?B?VmFuZXNzYQ==?=

      #3
      Re: How to detect when a tab page is being selected?

      Hi Stanimir,

      It worked like I needed!

      Thank you very much!
      Vanessa


      "Stanimir Stoyanov" wrote:
      Hi Vanessa,
      >
      Set the CausesValidatio n property of your TabControl to false. You don't
      have to handle its events either.
      >
      Best Regards,
      Stanimir Stoyanov
      www.stoyanoff.info
      >
      "Vanessa" <Vanessa@discus sions.microsoft .comwrote in message
      news:F79BB4E3-F826-429C-AAEA-5DE6D041E741@mi crosoft.com...
      Hi all!

      I have a tab control and in one tab page I have 8 textbox and 2 grids. The
      textbox are all numerics and have the following behavior: when I digit the
      2nd textbox then the 3rd textbox is updated with the 2nd more the
      difference
      between the 1st and 2nd, and so on.

      Example 1:
      TB 1: 10, TB 2: 20 -TB 3 will be updated with 30
      Example 2:
      TB 1: 15, TB 2: 30, TB 3: 45 -TB 4 will be updated with 60

      When I say "will be updated", it is updated on textbox_Validat ing() event.

      If I'd like to digit just 4 textbox, I left the 5th with zero (or blank)
      and
      it works fine. If I am on the 4th textbox and then click on one of the
      grids,
      it is ok too. But if the focus is on the 4th textbox (with some value
      greater
      than 0), and I click on another page of the tab control, it is not
      working.
      The problem is that on textbox_Validat ing() event, where I have the
      following
      test:

      private void textbox_Validat ing(object sender, CancelEventArgs e)
      {
      TextBox tb = sender as TextBox;
      if (tb.Focused == true)
      {
      UpdateNextTextb ox();
      }
      }

      In UpdateNextTextb ox() method I update the next number according I
      explained
      above and call Focus() event of the next textbox. When I click on the
      grid,
      the "if (tb.Focused == true)" is false and the next textbox will not be
      updated, and it is ok. The problem is that if I click on another tab page,
      this "if" is true, i.e., the focus is still on the textbox, and the next
      textbox is updated, what is wrong.

      I already tried Selecting(), Deselecting(), SelectedIndexCh anged() and
      other
      events of tab control, but all them are called after textbox_Validat ing().
      So
      what I want is to know if it is changing tab page before
      textbox_Validat ing(). Any idea?

      Thank you!
      Vanessa
      >

      Comment

      Working...