Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C# .Net 2008 TabControl - How to reference dynamically created child controls

  • 05-03-2009 4:57pm
    #1
    Registered Users, Registered Users 2 Posts: 7,265 ✭✭✭


    Hi guys,

    I'm stumped. I've trawled through the net over the past few days and can't seem to find a solution.
    • I have a Windows Form in C# .Net.
    • On that form, I have a tab control.
    • At run time, I generate a dynamic amount of tabs. Each tab contains an instance of a custom control that I created.
    • How can I reference a SPECIFIC instance of that control. eg, the control on tab 3.

    I need to be able to explicitly reference the custom control so I can access it's properties and methods.

    Any help, greatly appreciated.

    *EDIT* I'll accept an answer in VB.Net too :)


Comments

  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    Surely if you are creating the tabs at runtime you are also creating each tab's content so therefore you should have access to all controls on that tab?

    Either way, Im sure querying a tab's TabPage's property for the tab you are looking for than iterating through that tabpage's Control property for the control you are looking for would to the job too.


  • Registered Users, Registered Users 2 Posts: 7,265 ✭✭✭RangeR


    lynchie wrote: »
    Surely if you are creating the tabs at runtime you are also creating each tab's content so therefore you should have access to all controls on that tab?

    Either way, Im sure querying a tab's TabPage's property for the tab you are looking for than iterating through that tabpage's Control property for the control you are looking for would to the job too.

    Don't call me Surely :)

    I know I have access to each tab and each control on each tab but my question remains. How do I reference a specific control on a given tab without knowing the name of the control. I MAY give the custom controls dynamic names and keep a collection reference array but seems like a lot of fuss for a relatively simple problem.

    So I suppose something like TabControl.TabPages[2].Controls[0].blah as it will ALWAYS be the only control on the tab.

    *EDIT* Resolved. I bit the bullet and did it a semi long way instead. I just did a "foreach" on all controls on the tab and referenced it that way [after casting it]. But I would prefer a one liner like
    TabControl.TabPages[2].Controls[0].blah
    


Advertisement