To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
The ASP.NET Chart Control
Article :: Introduction to SharePoint Development in Visual Studio 2010
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Dec 19th, 2009, 07:34 AM   #1
EntityX
Hyperactive Member
 
EntityX's Avatar
 
Join Date: Feb 07
Location: Omnipresence
Posts: 477
EntityX is on a distinguished road (10+)
Resolved [RESOLVED] Want to check all labels on form to see if Label name has certain string within it.

I have a form that has a large number of labels. Is there a way I can move the focus from label to label. After I move the focus I'll check if the name of the label has a certain string in it. If it does then I'll leave the focus at that label. If it doesn't I'll move the focus to the next label and check if that label name has the string in it. I just need to know how to move the focus from label to label. I was trying SelectNextControl without success. Maybe I can tab programmatically to the next label but I don't know how to do that.
__________________
Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

"Persistence is the magic of success." Paramahansa Yogananda
EntityX is offline   Reply With Quote
Old Dec 19th, 2009, 07:52 AM   #2
gep13
ASP.Nut
 
gep13's Avatar
 
Join Date: Nov 04
Location: The Granite City
Posts: 14,451
gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)
Re: Want to check all labels on form to see if Label name has certain string within i

Hey,

Have you seen jm's post here:

http://www.vbforums.com/showthread.php?t=387308

I think this might help you. Check each control to see if it is a Label, and if it is, do the check that you need.

Hope that helps!!

Gary
__________________
Remember to mark your thread as resolved. Check out the new Forum features, including tagging here. Remember to rate posts that help.

My Site - ASP.Net Website running on CentOS 5.3 with Mono
My Blog - Blog on Aberdeen Developers .Net User Group
View my MCP Certifications

Free Stuff: WebsiteSpark|DreamSpark|BizSpark
Learning Resources: MSDN|LearnVisualStudio|TrainingSpot|ScottGu's Blog|ASP.Net Starter Kits|Regex|RegExLib
Useful Tools: XPath Builder|UltraMon|RegExBuddy|CopySourceAsHtml|TracExplorer|SQLyog|Chart Controls for .Net|SharePoint Designer|CodeRush Express
Coding Links: XPath|ConnectionStrings|VB and MySQL|MySQL Connector.Net|My.Settings
ADO.Net: MSDN Reference|Introduction|Using Access|Always use Parameters|Save and Retrieve Data - jm|An Explanation - jm
Code Bank Submissions: Code Snippets|Profile Provider|Serialization: C# VB|Restricted Menu|Compressed HttpWebRequest|Enumerate and Add Internet Explorer Favourites: VB C#|C# Tabbed Web Browser|Enhanced Tabbed Web Browser: VB C#
gep13 is offline   Reply With Quote
Old Dec 19th, 2009, 07:53 AM   #3
.paul.
PowerPoster
 
Join Date: May 07
Location: Chelmsford UK
Posts: 8,268
.paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+)
Re: Want to check all labels on form to see if Label name has certain string within i

try this:

vb Code:
  1. for each ctrl as control in me.controls
  2.     ctrl.focus
  3.     if ctrl.name.contains("string") then exit for
  4. next
.paul. is offline   Reply With Quote
Old Dec 19th, 2009, 07:53 AM   #4
mickey_pt
Frenzied Member
 
mickey_pt's Avatar
 
Join Date: Sep 06
Location: Corner of the Europe :)
Posts: 1,735
mickey_pt has a spectacular aura about (150+)mickey_pt has a spectacular aura about (150+)
Re: Want to check all labels on form to see if Label name has certain string within i

You cant select labels with selectnextcontrol...

You can do something like:
vb.net Code:
  1. For Each ctrl As Control In Me.Controls
  2.             If TypeOf ctrl Is Label Then
  3.                 Me.ActiveControl = ctrl
  4.                 MsgBox(Me.ActiveControl.Name)
  5.             End If
  6.         Next
__________________

Rate People That Helped You
Mark Thread Resolved When Resolved
mickey_pt is offline   Reply With Quote
Old Dec 19th, 2009, 07:58 AM   #5
gep13
ASP.Nut
 
gep13's Avatar
 
Join Date: Nov 04
Location: The Granite City
Posts: 14,451
gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)gep13 is a name known to all (1000+)
Re: Want to check all labels on form to see if Label name has certain string within i

Hey,

Am I not right in saying that to use each of the above approaches, you would also need to recurse into each control to see whether it had additional child controls? i.e. if there is a Panel on the form.

That is why I suggested jm's approach, as this recursion is not needed.

Gary
__________________
Remember to mark your thread as resolved. Check out the new Forum features, including tagging here. Remember to rate posts that help.

My Site - ASP.Net Website running on CentOS 5.3 with Mono
My Blog - Blog on Aberdeen Developers .Net User Group
View my MCP Certifications

Free Stuff: WebsiteSpark|DreamSpark|BizSpark
Learning Resources: MSDN|LearnVisualStudio|TrainingSpot|ScottGu's Blog|ASP.Net Starter Kits|Regex|RegExLib
Useful Tools: XPath Builder|UltraMon|RegExBuddy|CopySourceAsHtml|TracExplorer|SQLyog|Chart Controls for .Net|SharePoint Designer|CodeRush Express
Coding Links: XPath|ConnectionStrings|VB and MySQL|MySQL Connector.Net|My.Settings
ADO.Net: MSDN Reference|Introduction|Using Access|Always use Parameters|Save and Retrieve Data - jm|An Explanation - jm
Code Bank Submissions: Code Snippets|Profile Provider|Serialization: C# VB|Restricted Menu|Compressed HttpWebRequest|Enumerate and Add Internet Explorer Favourites: VB C#|C# Tabbed Web Browser|Enhanced Tabbed Web Browser: VB C#
gep13 is offline   Reply With Quote
Old Dec 19th, 2009, 10:22 AM   #6
EntityX
Hyperactive Member
 
EntityX's Avatar
 
Join Date: Feb 07
Location: Omnipresence
Posts: 477
EntityX is on a distinguished road (10+)
Re: Want to check all labels on form to see if Label name has certain string within i

Thanks for the help. .paul your code works perfectly. Perfectly that is the first time but for some reason if I close the form and change the string to something else and then reopen the form it goes to the first result every time. I tried setting ctrl = nothing before closing the form but it doesn't change anything. Not sure why. I'm putting the code in the form load sub.

I've checked to see that the string is changing and it is but once the form opens at a certain position going to the correct label it keeps on opening at the same position even though the string is changing to something that is found in some other label name for that form. I looked at jmc's code and I get the same problem using his method.

I tried setting the focus to the first label on the form before running the code but it doesn't fix the problem.
__________________
Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

"Persistence is the magic of success." Paramahansa Yogananda
EntityX is offline   Reply With Quote
Old Dec 19th, 2009, 10:36 AM   #7
.paul.
PowerPoster
 
Join Date: May 07
Location: Chelmsford UK
Posts: 8,268
.paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+)
Re: Want to check all labels on form to see if Label name has certain string within i

delete your binaries + rebuild

thats your bin/debug folder
.paul. is offline   Reply With Quote
Old Dec 19th, 2009, 10:46 AM   #8
.paul.
PowerPoster
 
Join Date: May 07
Location: Chelmsford UK
Posts: 8,268
.paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+)
Re: Want to check all labels on form to see if Label name has certain string within i

if that didn't work...
what are the names of the 2 controls + what are you searching for?
.paul. is offline   Reply With Quote
Old Dec 19th, 2009, 11:46 AM   #9
EntityX
Hyperactive Member
 
EntityX's Avatar
 
Join Date: Feb 07
Location: Omnipresence
Posts: 477
EntityX is on a distinguished road (10+)
Re: Want to check all labels on form to see if Label name has certain string within i

OK. I tried deleting both the bin and obj(has debug folder in it) folders and did a rebuild and the problem is still there.

On a particular first trial the string st5 = "Dph". I open the form with all the labels and it goes to LabelDph just like it should. I close the form and click in a different combobox ComboBoxBph. st5 = "Bph" now since I use :
Code:
   st5 = Me.ActiveControl.Name
   st5 = st5.Replace("ComboBox", "")
I reopen the form with all the labels and it still goes to LabelDph and not LabelBph which is way above it on the Form.

I used st6 to see what ctrl.Name is and it's LabelDph in the first case and LabelBph in the second case even though the form is opening at the LabelDph position in both cases.

Code:
   For Each ctrl In Me.Controls
        ctrl.Focus()
        If ctrl.Name.Contains(st5) Then
             st6 = ctrl.Name
             Exit For
        End If
   Next
If I could make the second, third, etc. opening of the form respond like the first then I'd be ok.

If I click in ComboBoxBph first and then open the form with all the labels then it will open at LabelBph. If I then closed the form clicked in ComboBoxDph and then opened the form it would open at LabelBph again. It always gets the first opening of the form right and it always keeps the same position at all openings of the form after that until I close my application and start it up again.
__________________
Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

"Persistence is the magic of success." Paramahansa Yogananda

Last edited by EntityX; Dec 19th, 2009 at 11:56 AM.
EntityX is offline   Reply With Quote
Old Dec 19th, 2009, 12:45 PM   #10
EntityX
Hyperactive Member
 
EntityX's Avatar
 
Join Date: Feb 07
Location: Omnipresence
Posts: 477
EntityX is on a distinguished road (10+)
Re: Want to check all labels on form to see if Label name has certain string within i

I created a new project from scratch. Made it very simple. 2 labels on the form that opens and I had the same problem even when using different code. I tried using Me.AutoScrollPosition = New Point(0, 1100) and Me.AutoScrollPosition = New Point(0, 0). And it would again open at the proper position the first time but would keep opening at the same position after that. I traced it to using Form2.ShowDialog()instead of using Form2.Show(). If I use Show instead of ShowDialog then the problem disappears. Thanks for your help everyone.
__________________
Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

"Persistence is the magic of success." Paramahansa Yogananda
EntityX is offline   Reply With Quote
Old Dec 19th, 2009, 12:41 PM   #11
mickey_pt
Frenzied Member
 
mickey_pt's Avatar
 
Join Date: Sep 06
Location: Corner of the Europe :)
Posts: 1,735
mickey_pt has a spectacular aura about (150+)mickey_pt has a spectacular aura about (150+)
Re: Want to check all labels on form to see if Label name has certain string within i

I'm a little bit confused...

You're trying to change the label names at runtime, and expect the second time you open the form the name it's the new one?
When you say close the form, you say close the application?
__________________

Rate People That Helped You
Mark Thread Resolved When Resolved
mickey_pt is offline   Reply With Quote
Old Dec 19th, 2009, 12:47 PM   #12
.paul.
PowerPoster
 
Join Date: May 07
Location: Chelmsford UK
Posts: 8,268
.paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+).paul. is a name known to all (1000+)
Re: Want to check all labels on form to see if Label name has certain string within i

try changing this:

vb Code:
  1. If ctrl.Name.Contains(st5) Then

to:

vb Code:
  1. if typeof ctrl is label andalso ctrl.Name.Contains(st5) Then
.paul. is offline   Reply With Quote
Old Dec 19th, 2009, 12:54 PM   #13
EntityX
Hyperactive Member
 
EntityX's Avatar
 
Join Date: Feb 07
Location: Omnipresence
Posts: 477
EntityX is on a distinguished road (10+)
Re: Want to check all labels on form to see if Label name has certain string within i

An explanation for mickey pt :

The second form in my large application was a form to explain the settings that are seen on a form that has numerous ComboBoxes. So I have ComboBoxBph and ComboBoxDph, etc, etc, on one form and then you click a button Explain Settings and another form opens with explanations of the settings that you change with the ComboBoxes. So LabelBph on form ExplainSettings would explain setting Bph which is alterred using ComboBoxBph which is on the first form and not on the form that has the explanations.
__________________
Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

"Persistence is the magic of success." Paramahansa Yogananda
EntityX is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:42 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.