-
Jul 23rd, 2021, 09:50 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] How to find control by tag property
Hi,
Is there a way to find a control by tag text without looping through the controls of the container?
I usually fidn controls by ID/name by:
Code:
Dim Thiscontrol As Control =MyPanel.Controls.Find("TXTbox_CaseID", True)(0)
But can we find a control by tag in such method?
Thanks.
-
Jul 23rd, 2021, 11:31 AM
#2
Re: How to find control by tag property
Code:
Thiscontrol As Control =MyPanel.Controls("TXTbox_CaseID")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 23rd, 2021, 12:40 PM
#3
Thread Starter
Fanatic Member
Re: How to find control by tag property
Will that consider the control's tag?
-
Jul 23rd, 2021, 02:19 PM
#4
Re: How to find control by tag property
What exactly does the tag contain? Why mention the name of the textbox if you want to find by tag?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 23rd, 2021, 02:27 PM
#5
Re: How to find control by tag property
Is the tag changing? If not, then I assume that you put something in the tag. At the same time, you could put the control into a Dictionary(of String,Control), with the key being the tag. That would be a particularly fast lookup, but it would require that the tags all be unique (I assume they are, or any other search won't work, either), and it gets to be a nuisance if the tags are changing.
My usual boring signature: Nothing
-
Jul 23rd, 2021, 02:35 PM
#6
Thread Starter
Fanatic Member
Re: How to find control by tag property
The tag is just some string text.
-
Jul 23rd, 2021, 02:36 PM
#7
Thread Starter
Fanatic Member
Re: How to find control by tag property
Originally Posted by .paul.
What exactly does the tag contain? Why mention the name of the textbox if you want to find by tag?
The tag is just some string text.
And it is because I have a few panels where I have some combo on each and those specific combos all have the same tag but only one at the time is visible depending on the user's selection.
So, I need to know which of those combos I need to access. I know which panel is visible at time, just need to know which combo is it that I need to populate. They have different names obviously but the tag is the same.
So, my idea was to look for the combo on that visible panel that has specific tag and populate it. Of course I could also loop through the controls onthe visibel panel and find that combo with the specific tag but I thought maybe I just could fidn the control as mentioned above.
-
Jul 23rd, 2021, 02:41 PM
#8
Thread Starter
Fanatic Member
Re: How to find control by tag property
The tag is constant.
So, lets say I have 10 panels and they all have, among other things, 4 combos that I need to populate differently based on the user selection and some other ramifications.
There are 4 unique tags that I assigned one to each of those combos on each panels.
Maybe my design is stupid and have to rethink it. I will check that dictionary thing.
-
Jul 23rd, 2021, 03:33 PM
#9
Re: How to find control by tag property
Code:
Dim Thiscontrol As Control = MyPanel.Controls.OfType(Of ComboBox).Where(Function(cb) cb.Tag = yourTagVariable).First
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 23rd, 2021, 03:46 PM
#10
Thread Starter
Fanatic Member
Re: How to find control by tag property
Originally Posted by .paul.
Code:
Dim Thiscontrol As Control = MyPanel.Controls.OfType(Of ComboBox).Where(Function(cb) cb.Tag = yourTagVariable).First
Thanks so much It does exactly what I was looking for.
Thanks again.
-
Jul 23rd, 2021, 04:04 PM
#11
Re: [RESOLVED] How to find control by tag property
Actually, you can change that…
Dim Thiscontrol As ComboBox = ‘etc…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 24th, 2021, 12:54 AM
#12
Re: [RESOLVED] How to find control by tag property
There's no need to call Where and then First. The First and similar methods allow you to specify a filter:
vb.net Code:
Dim Thiscontrol As ComboBox = MyPanel.Controls.OfType(Of ComboBox).First(Function(cb) cb.Tag = yourTagVariable)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|