Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
TabControl1.SelectedTab.Controls(4).Text =”Test”

How to do with this control without control Number. ?
(Is any way to handle with Control Name)
Posted

VB
dim tp as Control = TabControl1.SelectedTab.Controls(4)
tp.Text = "test"
 
Share this answer
 
v2
Comments
pradeep20912 21-Aug-13 7:50am    
Sir, Thanks for Reply,
I want to do without index No.
Eg.Controls(4) here also use "4"

If Controls(4) = "IDLBL" (Label) ---> I need to do with "IDLBL"
Ok, let's say you are looking for a button control on a tabPage in your tab control. This is how you would do it:

VB
Dim theControlYourLookingFor As Button

For Each ctrl As Control In TabControl1.SelectedTab.Controls
    If TypeOf(ctrl) is Button Then
        theControlYourLookingFor = CType(ctrl, Button)
        If theControlYourLookingFor.Name = "yourbutton" then
            ' your code here
        End If
    End If
Next


- Pete
 
Share this answer
 
v6
Comments
pradeep20912 22-Aug-13 1:43am    
Sir, Thanks for reply, I am beginner for Vb.Net
I need another thing,
I created Tab pages with controls(more than 100 controls in one tab page) in run time. (Number of Tab Pages depend on user input)

with some button,
AddHandler ReportBTN.Click, AddressOf MSub1

I used in "MSub1 sub" like this, its works
TabControl1.SelectedTab.Controls(12).Text= "Passed"

but,
Some time controls index not correct, (some time this control index not "12")

because of that I try to do with control name

Please tell me How to do this with good way,
(Sorry for my English)
Thanks
pdoxtader 22-Aug-13 8:47am    
I'm not sure what your asking me... The example I gave you will give you a reference to the button control you're looking for. If you run the code example I gave you, and then replace

"yourbutton" with the name of the button control your looking for, and:

' your code here

with

theControlYourLookingFor.Text = "Test"

You will accomplish what you need... you will have found a button control by it's name, and set it's text.

Also, a little bit of friendly advice: Use descriptive variable / object names, use Camel Case, and replace the default designer set names immediately. The compiler will discard the names you choose anyway, so there's no penalty for using a name like backgroundThreadCreatedAfterAppStart, or something like that.

We use descriptive names so that other people reading your code won't need to spend so much time trying to figure out what the purpose of a sub or function is, and it's much easier to understand. Even if no one else will ever read your code, imagine coming back to this project a year or three down the road, and trying to remember and figure out what YOU were doing...

Readability is everything.

- Pete

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900