Connecting Tech Pros Worldwide Forums | Help | Site Map

Control name from tabindex

Newbie
 
Join Date: Sep 2008
Posts: 1
#1: Sep 28 '08
Hello people,
How I can retrive the control name (ex: textBox12) from a known tabindex (ex: 12).

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,768
#2: Sep 28 '08

re: Control name from tabindex


I'm not sure I know which control you are trying to get the name of.
Is it that you want the name of a text box on the tab control, or that you want the name of the tab control itself?

A tabcontrol has a collection of TabPages.
A TabPage as a collection of Controls.

So you can loop through all the TabPages and within that loop through all its Controls to get their names. But you need a way to know you have gotten the right control. If your TabPage only has one TextBox for example then it becomes significantly easier because you loop through all the controls until you find the one whose type is TextBox. But if you have a lot of TextBoxes it becomes a problem. You could do a lot of fancy switch and if logic... Maybe identify it based on its TabIndex which should be the same from TabPage to TabPage...

Or, since you had to build the controls and put them on the TabPages to begin with, it might be best to assign the names as you build the TabPages. Now you know the name before its ever displayed and it will retain that name for its lifespan or until you change it programmaticly.
Reply