Newbit: help with TabPage and Controls 
Author Message
 Newbit: help with TabPage and Controls

I have a TabControl with many TabPages and on each TabPage I have a
listbox that I need to populate when the user selects a TabPage.  I
use the following event to trap which tabpage is selected:

private void noteTabControl_SelectedIndexChanged(object sender,
System.EventArgs e)
{
        SubGroup sgrp1;
        ListBox lst1;

        // Get the Tabcontrol Object
        TabControl ctrl = (TabControl)sender;

        // Get the TabPage Tag Object
        sgrp1 = (SubGroup)ctrl.SelectedTab.Tag;

        // I would like to populate the listbox in the TabPage here

        ...

Quote:
}

How can I now reference the listbox on the TabPage?

Thanks,

Don



Fri, 03 Jun 2005 01:32:40 GMT  
 Newbit: help with TabPage and Controls
Hello Don,

You may find the ListBox in the TabPage by iterating all controls on the
TabPage, if found one control is of ListBox type then use it. This is a
sample code:

private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
        // Get the Tabcontrol Object
        TabControl tab = (TabControl)sender;

        // Find the ListBox control with an iteration
        ListBox lst1;
        foreach(Control ctrl in tab.SelectedTab.Controls)
                if(ctrl is ListBox)
                        lst1 = (ListBox)ctrl;

        // Process the ListBox if it is not null
        if(lst1 != null)
                Console.WriteLine(lst1.ToString());

Quote:
}

Please Note: you need to ensure there is only one ListBox in each TabPage,
or the loop can not find the correct one.

I hope this helps you.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Newsgroups: microsoft.public.dotnet.languages.CSharp
    Subject: Newbit: help with TabPage and Controls

    X-Newsreader: Forte Agent 1.92/32.572
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Lines: 27
    Date: Sun, 15 Dec 2002 17:32:40 GMT
    NNTP-Posting-Host: 24.136.242.24

    X-Trace: tornadotest1.news.pas.earthlink.net 1039973560 24.136.242.24
(Sun, 15 Dec 2002 09:32:40 PST)
    NNTP-Posting-Date: Sun, 15 Dec 2002 09:32:40 PST
    Organization: EarthLink Inc. -- http://www.EarthLink.net
    Path:
cpmsftngxa06!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de!news.stealth
net!news.stealth.net!news.astraweb.com!news-small.astraweb.com!newsfeed.new
s2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.ear
thlink.net!tornadotest1.news.pas.earthlink.net.POSTED!not-for-mail
    Xref: cpmsftngxa06 microsoft.public.dotnet.languages.csharp:116565
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    I have a TabControl with many TabPages and on each TabPage I have a
    listbox that I need to populate when the user selects a TabPage.  I
    use the following event to trap which tabpage is selected:

    private void noteTabControl_SelectedIndexChanged(object sender,
    System.EventArgs e)
    {
        SubGroup sgrp1;
        ListBox lst1;

        // Get the Tabcontrol Object
        TabControl ctrl = (TabControl)sender;

        // Get the TabPage Tag Object
        sgrp1 = (SubGroup)ctrl.SelectedTab.Tag;

        // I would like to populate the listbox in the TabPage here

        ...
    }

    How can I now reference the listbox on the TabPage?

    Thanks,

    Don



Sat, 04 Jun 2005 09:52:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbit question on ADO

2. Newbit: need opinion from experienced Windows Programmers

3. TabPage question

4. How to display richtextbox scrollbars on a tabpage?

5. Adding objects to a tabpage programmitically

6. TabControl tabpage change

7. Catching the TabPage change event?

8. Broken Show() and Hide() for Forms.Form.TabPage

9. dynamically adding separately created tabpage to tabcontrol

10. Hide a TabPage

11. is it possible to show Form on TabPage ?

12. TabPage - OnChange

 

 
Powered by phpBB® Forum Software