|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Loop thru WinForm ControlsHi All
What is the code to loop thru all textbox controls on a form? TIA johnb Am 10.04.2010 17:53, schrieb johnb:
> Hi All Inside the Form itself only or also inside other containers on the Form?> What is the code to loop thru all textbox controls on a form? The former (it's shorter ;-) ): 'assuming option infer on for each c in controls if typeof c is textbox then with directcast(c, textbox) .property = value end with end if next -- Armin Hi Guys
Thank you for the help. I've now cracked it. johnb Show quoteHide quote "Armin Zingler" wrote: > Am 10.04.2010 17:53, schrieb johnb: > > Hi All > > What is the code to loop thru all textbox controls on a form? > > Inside the Form itself only or also inside other containers on the Form? > The former (it's shorter ;-) ): > > 'assuming option infer on > for each c in controls > if typeof c is textbox then > with directcast(c, textbox) > .property = value > end with > end if > next > > > -- > Armin > . > "johnb" <jo***@discussions.microsoft.com> wrote in message The Form class (which derives from Control) has a Controls property:news:A2474CF4-69FB-4320-B080-CD45BDE16757@microsoft.com... > Hi All > What is the code to loop thru all textbox controls on a form? > > TIA > johnb http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx which is a collection of type Control. The Control class has a GetType() method to allow you to determine if the current control is a TextBox. http://msdn.microsoft.com/en-us/library/system.object.gettype(v=VS.90).aspx Peter,
I've seen that the getType is currently more popular, but why not the way we here in this newsgroup has done it forever. If Typeof object Is Classname? http://www.vb-tips.com/ControlBorder.aspx Is this a kind of verCSharping (I don't know if you knows a tiny little bit Dutch, then you understand it) It means something as: using C# ways, where there is a very good VB alternative. :-) CorShow quoteHide quote "PvdG42" <pvd***@toadstool.edu> wrote in message news:OIbe1rM2KHA.1016@TK2MSFTNGP02.phx.gbl... > > "johnb" <jo***@discussions.microsoft.com> wrote in message > news:A2474CF4-69FB-4320-B080-CD45BDE16757@microsoft.com... >> Hi All >> What is the code to loop thru all textbox controls on a form? >> >> TIA >> johnb > > The Form class (which derives from Control) has a Controls property: > > http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx > > which is a collection of type Control. > > The Control class has a GetType() method to allow you to determine if the > current control is a TextBox. > > http://msdn.microsoft.com/en-us/library/system.object.gettype(v=VS.90).aspx > > >
Show quote
Hide quote
"Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> wrote in message I'm not trying to start anything, just trying to offer the OP a way the news:#0gPtKN2KHA.4752@TK2MSFTNGP02.phx.gbl... > Peter, > > I've seen that the getType is currently more popular, but why not the way > we here in this newsgroup has done it forever. > > If Typeof object Is Classname? > > http://www.vb-tips.com/ControlBorder.aspx > > Is this a kind of verCSharping (I don't know if you knows a tiny little > bit Dutch, then you understand it) > > It means something as: using C# ways, where there is a very good VB > alternative. > > :-) > > Cor > "learn to fish". Your way is certainly just as good, and certainly more VB-traditional. Am 11.04.2010 03:39, schrieb PvdG42:
>> But you did. :-)> I'm not trying to start anything, > just trying to offer the OP a way the I'm not a native English speaker, so what does "*just* as good" mean> "learn to fish". > Your way is certainly just as good, in _this_ case? :) "ok, use it if you want", or "as good as", or "better than"? I say TypeOf is to be preferred because it's "just quicker". About 3.5x quicker (in my personal, I predict that one will say disputable, tests). (yes, and I do know that both methods are not the same because TypeOf includes inherited classes). And, BTW, TypeOf is 1:1 translated to the "isinst" IL keyword. > and certainly more VB-traditional. Curly braces in C are also traditional. AND THAT DAMNEDCASE SENSITIVITY TOOOOO! Ummm... sorry, Sunday morning... ;) -- Armin
Show quote
Hide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message Then, I should have said "you way is better". I stand corrected.news:#Z7Zs9V2KHA.1708@TK2MSFTNGP05.phx.gbl... > Am 11.04.2010 03:39, schrieb PvdG42: >>> >> I'm not trying to start anything, > > But you did. :-) > >> just trying to offer the OP a way the >> "learn to fish". >> Your way is certainly just as good, > > I'm not a native English speaker, so what does "*just* as good" mean > in _this_ case? :) "ok, use it if you want", or "as good as", or > "better than"? > > I say TypeOf is to be preferred because it's "just quicker". > About 3.5x quicker (in my personal, I predict that one will say > disputable, tests). (yes, and I do know that both methods are not the same > because TypeOf includes inherited classes). And, BTW, TypeOf is 1:1 > translated to the "isinst" IL keyword. > >> and certainly more VB-traditional. > > Curly braces in C are also traditional. AND THAT DAMNED > CASE SENSITIVITY TOOOOO! Ummm... sorry, Sunday morning... ;) > > > -- > Armin Thanks, Armin. I was not aware of the significant performance difference. Hi Guys
Thank you for your useful comments. Yeah I'm learning to fish with this one but good have more than one rod in the bag. Thanks once more johnb Show quoteHide quote "Cor Ligthert[MVP]" wrote: > Peter, > > I've seen that the getType is currently more popular, but why not the way we > here in this newsgroup has done it forever. > > If Typeof object Is Classname? > > http://www.vb-tips.com/ControlBorder.aspx > > Is this a kind of verCSharping (I don't know if you knows a tiny little bit > Dutch, then you understand it) > > It means something as: using C# ways, where there is a very good VB > alternative. > > :-) > > Cor > > "PvdG42" <pvd***@toadstool.edu> wrote in message > news:OIbe1rM2KHA.1016@TK2MSFTNGP02.phx.gbl... > > > > "johnb" <jo***@discussions.microsoft.com> wrote in message > > news:A2474CF4-69FB-4320-B080-CD45BDE16757@microsoft.com... > >> Hi All > >> What is the code to loop thru all textbox controls on a form? > >> > >> TIA > >> johnb > > > > The Form class (which derives from Control) has a Controls property: > > > > http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx > > > > which is a collection of type Control. > > > > The Control class has a GetType() method to allow you to determine if the > > current control is a TextBox. > > > > http://msdn.microsoft.com/en-us/library/system.object.gettype(v=VS.90).aspx > > > > > > > . > "johnb" <jo***@discussions.microsoft.com> wrote in message Pay close attention to Armin's latest post. Note the significant improvement news:B80896B0-AC66-4C80-B685-3D065334E578@microsoft.com... > Hi Guys > > Thank you for your useful comments. Yeah I'm learning to fish with this > one > but good have more than one rod in the bag. > > Thanks once more > > johnb > difference using TypeOf.
Event of changing the grid-cell value.
Change state of detached column of dataGridView. AutoFilter method of Range class failed Creating Drive Partitions Error 30366 in VB behind VS(2005) project Outlook like Calendar for VB net Copy Word Doc Bookmarks from One Document to another (VB.net) Owner Drawn form background problems Treeview duplicate nodes (VB.NET 2008) Gridview order |
|||||||||||||||||||||||