tab control and tab changed

  • Thread starter Thread starter Lance Johnson
  • Start date Start date
L

Lance Johnson

I would like for when a tab page changes, that my controls on the previous
tab page would receive a visiblechanged event or some other event so they
are aware of that. We have db locks in some of our controls when they're
visible and so if a tab page is changed, I would like for the control to
know it's no longer visible and release that lock. Currently that doesn't
happen. Does anybody have any suggestions and/or is this a bug?

Lance Johnson
 
Lance Johnson said:
I'm well aware of that event, however that does me
no good for notifying my client controls for the
previous tab. I'd rather not use the workaround of
remembering the last tab page manually.

When SelectedIndexChanged occurs, you could use a foreach statement to
iterate over the TabPages in your TabControl and disable the controls on any
TabPage that isn't the currently selected one.

P.
 
I could do that, however what could I call that would allow the control to
know it's not visible any more. If I set control.visible to false that does
nothing, because it's already set to false. That's my #1 problem is that
it's visibility gets set to false without the event occurring.

Lance Johnson
 
Hi Lance,

In SelectedIndexChanged event, you can only get the current selected tab
index.
I think you should get the original tab before changing, then you can loop
through the
controls in the original tab and invoke its related method.

To get the original tab, you can set a static variable to store the
original tab index(at startup its value should be 0).

To loop through the controls on the tab, you can do like this:

foreach(Control c in tabControl1.TabPages[origtabindex].Controls)
{
//invoke your method of the control
}

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Lance Johnson" <[email protected]>
| References: <[email protected]>
<#[email protected]>
| Subject: Re: tab control and tab changed
| Date: Tue, 26 Aug 2003 15:25:14 -0500
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.95.153.41
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:179632
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I'm well aware of that event, however that does me no good for notifying
my
| client controls for the previous tab. I'd rather not use the workaround
of
| remembering the last tab page manually. When my client controls are
hidden
| that event should be thrown, which it's not being thrown. As a side note
| I've built in an event handler on my control that attaches to the parent's
| visible changed event so it'll know to hide itself.
|
| Lance Johnson
|
| | > Use TabControl.SelectedIndexChanged event.
| >
| > | > > I would like for when a tab page changes, that my controls on the
| previous
| > > tab page would receive a visiblechanged event or some other event so
| they
| > > are aware of that. We have db locks in some of our controls when
| they're
| > > visible and so if a tab page is changed, I would like for the control
to
| > > know it's no longer visible and release that lock. Currently that
| doesn't
| > > happen. Does anybody have any suggestions and/or is this a bug?
| > >
| > > Lance Johnson
| > >
| > >
| >
| >
|
|
|
 
Hi Lance,

I think you should inherit a new class from your control and custom some
methods
to your control(such as release lock).
Then, in the SelectedIndexChanged event, you can record the last invisable
tab index
and invoke all the related method of the controls in that tab page.
If I still misunderstand you, please do not be hesitated to tell me.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Lance Johnson" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]> <[email protected]>
| Subject: Re: tab control and tab changed
| Date: Tue, 26 Aug 2003 16:09:42 -0500
| Lines: 31
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.95.153.41
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:180048
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I could do that, however what could I call that would allow the control to
| know it's not visible any more. If I set control.visible to false that
does
| nothing, because it's already set to false. That's my #1 problem is that
| it's visibility gets set to false without the event occurring.
|
| Lance Johnson
|
| | >
| > > > Use TabControl.SelectedIndexChanged event.
| > >
| > > I'm well aware of that event, however that does me
| > > no good for notifying my client controls for the
| > > previous tab. I'd rather not use the workaround of
| > > remembering the last tab page manually.
| >
| > When SelectedIndexChanged occurs, you could use a foreach statement to
| > iterate over the TabPages in your TabControl and disable the controls on
| any
| > TabPage that isn't the currently selected one.
| >
| > P.
| >
| > --
| > www.CL4.org
| >
| >
|
|
|
 
I was just hoping there was a easier way of automatically doing this. What
I've done instead is to look at the parent changed event for the control and
subscribe to the Parent's visibility changed event. Seems to work well
enough for me and then all of my derived controls will automatically work
with no extra work on any tab control or anything else I might put them in.

Lance Johnson
 
Hi Lance,

I can reproduce your problem.
When clicking the tab page, the unvisabled control does not fire
VisibleChanged
event.
I have used Spy++ to watch the control's message when its parent tab page
get
unvisabled, finding that no message generated.

I also found that the control's VisibleChanged event fires go with the
WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED message.
I think the windows implement the control's visable change by changing their
z-order, when the control on the tab page was unvisabled, its absolute
z-order did
not change, but the visable tab page's z-order get up and lay over the
control, so
the VisibleChanged event did not fire.
While click the tab page that contains the control, the control's absolute
z-order needs
get up and VisibleChanged fired.

So you can not use this way of doing what you want, please try some way
that we suggested.
It will work around your problem.

Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Lance Johnson" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]> <[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: tab control and tab changed
| Date: Mon, 8 Sep 2003 11:24:27 -0500
| Lines: 87
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <OTB#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.95.153.41
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183222
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I was just hoping there was a easier way of automatically doing this.
What
| I've done instead is to look at the parent changed event for the control
and
| subscribe to the Parent's visibility changed event. Seems to work well
| enough for me and then all of my derived controls will automatically work
| with no extra work on any tab control or anything else I might put them
in.
|
| Lance Johnson
|
|
| | >
| > Hi Lance,
| >
| > I think you should inherit a new class from your control and custom some
| > methods
| > to your control(such as release lock).
| > Then, in the SelectedIndexChanged event, you can record the last
invisable
| > tab index
| > and invoke all the related method of the controls in that tab page.
| > If I still misunderstand you, please do not be hesitated to tell me.
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Lance Johnson" <[email protected]>
| > | References: <[email protected]>
| > <#[email protected]>
| > <[email protected]>
<[email protected]>
| > | Subject: Re: tab control and tab changed
| > | Date: Tue, 26 Aug 2003 16:09:42 -0500
| > | Lines: 31
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.95.153.41
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:180048
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I could do that, however what could I call that would allow the
control
| to
| > | know it's not visible any more. If I set control.visible to false
that
| > does
| > | nothing, because it's already set to false. That's my #1 problem is
| that
| > | it's visibility gets set to false without the event occurring.
| > |
| > | Lance Johnson
| > |
| > | | > | >
| > | > > > Use TabControl.SelectedIndexChanged event.
| > | > >
| > | > > I'm well aware of that event, however that does me
| > | > > no good for notifying my client controls for the
| > | > > previous tab. I'd rather not use the workaround of
| > | > > remembering the last tab page manually.
| > | >
| > | > When SelectedIndexChanged occurs, you could use a foreach statement
to
| > | > iterate over the TabPages in your TabControl and disable the
controls
| on
| > | any
| > | > TabPage that isn't the currently selected one.
| > | >
| > | > P.
| > | >
| > | > --
| > | > www.CL4.org
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|
 
That's very strange. You're saying that when a tab page gets change there's
no event happening on the tab page itself. Because I'm hooking into that
event and when I click on another tab it's firing for me and I'm able to
update my stuff correctly.

Lance Johnson
 
Hi Lance,

I think I did not express clear.
When click another tab page, the tab control will fire its event, but
the button control in the tab page does not fire the its VisibleChanged
Also, the button did not generate any message.


Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Lance Johnson" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]> <[email protected]>
<#[email protected]>
<[email protected]>
<OTB#[email protected]>
<[email protected]>
| Subject: Re: tab control and tab changed
| Date: Fri, 12 Sep 2003 16:26:22 -0500
| Lines: 171
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 204.95.153.41
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:184535
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| That's very strange. You're saying that when a tab page gets change
there's
| no event happening on the tab page itself. Because I'm hooking into that
| event and when I click on another tab it's firing for me and I'm able to
| update my stuff correctly.
|
| Lance Johnson
|
|
| | >
| > Hi Lance,
| >
| > I can reproduce your problem.
| > When clicking the tab page, the unvisabled control does not fire
| > VisibleChanged
| > event.
| > I have used Spy++ to watch the control's message when its parent tab
page
| > get
| > unvisabled, finding that no message generated.
| >
| > I also found that the control's VisibleChanged event fires go with the
| > WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED message.
| > I think the windows implement the control's visable change by changing
| their
| > z-order, when the control on the tab page was unvisabled, its absolute
| > z-order did
| > not change, but the visable tab page's z-order get up and lay over the
| > control, so
| > the VisibleChanged event did not fire.
| > While click the tab page that contains the control, the control's
absolute
| > z-order needs
| > get up and VisibleChanged fired.
| >
| > So you can not use this way of doing what you want, please try some way
| > that we suggested.
| > It will work around your problem.
| >
| > Hope this helps.
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Lance Johnson" <[email protected]>
| > | References: <[email protected]>
| > <#[email protected]>
| > <[email protected]>
<[email protected]>
| > <#[email protected]>
| > <[email protected]>
| > | Subject: Re: tab control and tab changed
| > | Date: Mon, 8 Sep 2003 11:24:27 -0500
| > | Lines: 87
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <OTB#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 204.95.153.41
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:183222
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | I was just hoping there was a easier way of automatically doing this.
| > What
| > | I've done instead is to look at the parent changed event for the
control
| > and
| > | subscribe to the Parent's visibility changed event. Seems to work
well
| > | enough for me and then all of my derived controls will automatically
| work
| > | with no extra work on any tab control or anything else I might put
them
| > in.
| > |
| > | Lance Johnson
| > |
| > |
| > | | > | >
| > | > Hi Lance,
| > | >
| > | > I think you should inherit a new class from your control and custom
| some
| > | > methods
| > | > to your control(such as release lock).
| > | > Then, in the SelectedIndexChanged event, you can record the last
| > invisable
| > | > tab index
| > | > and invoke all the related method of the controls in that tab page.
| > | > If I still misunderstand you, please do not be hesitated to tell me.
| > | >
| > | > Best regards,
| > | > Jeffrey Tan
| > | > Microsoft Online Partner Support
| > | > Get Secure! - www.microsoft.com/security
| > | > This posting is provided "as is" with no warranties and confers no
| > rights.
| > | >
| > | > --------------------
| > | > | From: "Lance Johnson" <[email protected]>
| > | > | References: <[email protected]>
| > | > <#[email protected]>
| > | > <[email protected]>
| > <[email protected]>
| > | > | Subject: Re: tab control and tab changed
| > | > | Date: Tue, 26 Aug 2003 16:09:42 -0500
| > | > | Lines: 31
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 204.95.153.41
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| > | > | Xref: cpmsftngxa06.phx.gbl
| > | microsoft.public.dotnet.languages.csharp:180048
| > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > | > |
| > | > | I could do that, however what could I call that would allow the
| > control
| > | to
| > | > | know it's not visible any more. If I set control.visible to false
| > that
| > | > does
| > | > | nothing, because it's already set to false. That's my #1 problem
is
| > | that
| > | > | it's visibility gets set to false without the event occurring.
| > | > |
| > | > | Lance Johnson
| > | > |
| > | > | | > | > | >
| > | > | > > > Use TabControl.SelectedIndexChanged event.
| > | > | > >
| > | > | > > I'm well aware of that event, however that does me
| > | > | > > no good for notifying my client controls for the
| > | > | > > previous tab. I'd rather not use the workaround of
| > | > | > > remembering the last tab page manually.
| > | > | >
| > | > | > When SelectedIndexChanged occurs, you could use a foreach
| statement
| > to
| > | > | > iterate over the TabPages in your TabControl and disable the
| > controls
| > | on
| > | > | any
| > | > | > TabPage that isn't the currently selected one.
| > | > | >
| > | > | > P.
| > | > | >
| > | > | > --
| > | > | > www.CL4.org
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
Back
Top