471,326 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

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_Validating() 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_Validating() event, where I have the following
test:

private void textbox_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if (tb.Focused == true)
{
UpdateNextTextbox();
}
}

In UpdateNextTextbox() 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(), SelectedIndexChanged() and other
events of tab control, but all them are called after textbox_Validating(). So
what I want is to know if it is changing tab page before
textbox_Validating(). Any idea?

Thank you!
Vanessa
Jul 15 '08 #1
2 7395
Hi Vanessa,

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

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info

"Vanessa" <Va*****@discussions.microsoft.comwrote in message
news:F7**********************************@microsof t.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_Validating() 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_Validating() event, where I have the
following
test:

private void textbox_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if (tb.Focused == true)
{
UpdateNextTextbox();
}
}

In UpdateNextTextbox() 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(), SelectedIndexChanged() and
other
events of tab control, but all them are called after textbox_Validating().
So
what I want is to know if it is changing tab page before
textbox_Validating(). Any idea?

Thank you!
Vanessa
Jul 15 '08 #2
Hi Stanimir,

It worked like I needed!

Thank you very much!
Vanessa
"Stanimir Stoyanov" wrote:
Hi Vanessa,

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

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info

"Vanessa" <Va*****@discussions.microsoft.comwrote in message
news:F7**********************************@microsof t.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_Validating() 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_Validating() event, where I have the
following
test:

private void textbox_Validating(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if (tb.Focused == true)
{
UpdateNextTextbox();
}
}

In UpdateNextTextbox() 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(), SelectedIndexChanged() and
other
events of tab control, but all them are called after textbox_Validating().
So
what I want is to know if it is changing tab page before
textbox_Validating(). Any idea?

Thank you!
Vanessa
Jul 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

157 posts views Thread by Dennis | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.