Search controls text

duelchamp1

Member
Joined
Aug 9, 2006
Messages
13
Programming Experience
Beginner
Hey

Can anyone tell me how to create a search feild that will when the user clicks a button search all the lables on the form and upon finding the right info will make that label visible.

Also if anyone knows of a better way to search for then show information I would be happy for the help

Thanks

Duelchamp1:)
 
You just need to loop through the controls collection and set that particular controls visible property to false...

VB.NET:
dim Lbl as label
 
For Each Ctrl as control in Me.Controls
If Ctrl.GetType is GetType(Label) then
lbl = DirectCast(Ctrl,label)
 
if lbl.whatever = whatever then
lbl.visible = True
end if
next
 
Hey thanks for the info I was hoping you might be able to show me how the code would look if when somone types into a text box "Mark" and then lblMark becomes visible Thanks
 
Just update duelchamps1's code to...

VB.NET:
dim Lbl as label
 
For Each Ctrl as control in Me.Controls
If Ctrl.GetType is GetType(Label) then
lbl = DirectCast(Ctrl,label)
 
[B]if lbl.Name = Textbox1.text then[/B]
lbl.visible = True
end if
next

You'd be better off using string comparison functions to get partial results...
 
that won't work aBsOlUt,

Label Name -> lblmark

Textbox text -> Mark

The string comparison wont do anything you'd need to do a substring to not include the first three letters. Also the = operator is waaaaaay slower than using the .equals function.

You could also use the tag property.
 
You use the String.IndexOf method to find an occurence of a string within another.
 
It will only work if the textbox text value is exactly the same as the labels name property.

I mentioned that if he wants to compare partial strings he'd be better off with string functions. My wording might have been a bit off.
 
Back
Top