Help!!! on getting control over Controls on VB.Net Forms
-
How to get all the controls in the form, like in VB we used to do for each ctrl in me if typeof ctrl is Textbox then ctrl.text = "" end if next How we do this in VB.Net.??? Thanks :)Be Humble in Victory and Strong in Defeat.:) -Het
The controls are in me.Controls. for each ctl as Control in me.Controls if TypeOf ctl Is TextBox Then ... next
-
The controls are in me.Controls. for each ctl as Control in me.Controls if TypeOf ctl Is TextBox Then ... next
was good one controls are in me, but, I tried out the code, i declared ctl as object, and gave the same code but it is giving me "syntax error ." thats what it is saying. so if u can help me out. Thanks again for ur reply :)Be Humble in Victory and Strong in Defeat.:) -Het
-
was good one controls are in me, but, I tried out the code, i declared ctl as object, and gave the same code but it is giving me "syntax error ." thats what it is saying. so if u can help me out. Thanks again for ur reply :)Be Humble in Victory and Strong in Defeat.:) -Het
ctl should to be Control, not Object. I tried this, without any errors: For Each ctl As Control In Me.Controls ctl.Text = "hier" Next
-
was good one controls are in me, but, I tried out the code, i declared ctl as object, and gave the same code but it is giving me "syntax error ." thats what it is saying. so if u can help me out. Thanks again for ur reply :)Be Humble in Victory and Strong in Defeat.:) -Het
Het2109 wrote: giving me "syntax error I tested that code myself in VB.NET
As [type]" syntax won't work try:Dim c As Control For Each c In Me.Controls If TypeOf c Is TextBox Then End If Next
-- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
-
Het2109 wrote: giving me "syntax error I tested that code myself in VB.NET
As [type]" syntax won't work try:Dim c As Control For Each c In Me.Controls If TypeOf c Is TextBox Then End If Next
-- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
-
ya, but suppose i have a group box and my textbox/combo box is placed on the group box, then how to access it. thru this code i get groupbox, but not the controls that are placed inside the groupbox. :)Be Humble in Victory and Strong in Defeat.:) -Het
Het2109 wrote: ya, but suppose i have a group box and my textbox/combo box is placed on the group box, then how to access it. thru this code i get groupbox, but not the controls that are placed inside the groupbox. Then handle that case in the loop, either by having a secondary loop, or better, set up the loop as a function that takes a controls collection as a parameter. eg:
Public Sub RecurseControls(ByVal ctls As ControlCollection) Dim c As Control For Each c In ctls If TypeOf c Is TextBox Then Debug.WriteLine(c.Text) ElseIf TypeOf c Is GroupBox Then RecurseControls(c.Controls) End If Next End Sub
You call this function, passing in Me.Controls to start with. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky