|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
vb.net; controlsIn vb6 a group of controls ie command buttons could be refered to by
an index number ie cmdWord(4). This was accomplished by using the index property of the control. Vb.net does not seem to have the index property for buttons. Is there a way in vb.net to refer to a group of controls in a way that includes a unique index number for the specific control to be used? Thanks, Howard Haisten jax1***@yahoo.com wrote:
> In vb6 a group of controls ie command buttons could be refered to by You could add all the button controls to an array on form load.> an index number ie cmdWord(4). This was accomplished by using the > index property of the control. Vb.net does not seem to have the index > property for buttons. Is there a way in vb.net to refer to a group of > controls in a way that includes a unique index number for the > specific control to be used? > > Thanks, > Howard Haisten For Each C as Control in Me.Controls if typeof C is Button then 'Add to Array end if End if This way, you do not know which button has what index in the array.
If you need to know this, you have to do it by hand, ie: Dim x(1) as button x(0)=button1 x(2)=button2 then you can use x in the same way as the controlarray in vb6 Chris wrote: Show quoteHide quote > jax1***@yahoo.com wrote: >> In vb6 a group of controls ie command buttons could be refered to by >> an index number ie cmdWord(4). This was accomplished by using the >> index property of the control. Vb.net does not seem to have the index >> property for buttons. Is there a way in vb.net to refer to a group of >> controls in a way that includes a unique index number for the >> specific control to be used? >> Thanks, >> Howard Haisten > > You could add all the button controls to an array on form load. > > For Each C as Control in Me.Controls > if typeof C is Button then > 'Add to Array > end if > End if Or a little bit more simple
Dim x() as button = {button1, button2} Just a little addition the solution is correct in my opinion, Cor Show quoteHide quote "Theo Verweij" <tverw***@xs4all.nl> schreef in bericht news:uWn7NPe%23GHA.4376@TK2MSFTNGP03.phx.gbl... > This way, you do not know which button has what index in the array. > If you need to know this, you have to do it by hand, ie: > > Dim x(1) as button > > x(0)=button1 > x(2)=button2 > > then you can use x in the same way as the controlarray in vb6 > > Chris wrote: >> jax1***@yahoo.com wrote: >>> In vb6 a group of controls ie command buttons could be refered to by >>> an index number ie cmdWord(4). This was accomplished by using the >>> index property of the control. Vb.net does not seem to have the index >>> property for buttons. Is there a way in vb.net to refer to a group of >>> controls in a way that includes a unique index number for the >>> specific control to be used? >>> Thanks, >>> Howard Haisten >> >> You could add all the button controls to an array on form load. >> >> For Each C as Control in Me.Controls >> if typeof C is Button then >> 'Add to Array >> end if >> End if Smart thinking Cor, I didn't think of this option.
Cor Ligthert [MVP] wrote: Show quoteHide quote > Or a little bit more simple > > Dim x() as button = {button1, button2} > > Just a little addition the solution is correct in my opinion, > > Cor > > "Theo Verweij" <tverw***@xs4all.nl> schreef in bericht > news:uWn7NPe%23GHA.4376@TK2MSFTNGP03.phx.gbl... >> This way, you do not know which button has what index in the array. >> If you need to know this, you have to do it by hand, ie: >> >> Dim x(1) as button >> >> x(0)=button1 >> x(2)=button2 >> >> then you can use x in the same way as the controlarray in vb6 >> >> Chris wrote: >>> jax1***@yahoo.com wrote: >>>> In vb6 a group of controls ie command buttons could be refered to by >>>> an index number ie cmdWord(4). This was accomplished by using the >>>> index property of the control. Vb.net does not seem to have the index >>>> property for buttons. Is there a way in vb.net to refer to a group of >>>> controls in a way that includes a unique index number for the >>>> specific control to be used? >>>> Thanks, >>>> Howard Haisten >>> You could add all the button controls to an array on form load. >>> >>> For Each C as Control in Me.Controls >>> if typeof C is Button then >>> 'Add to Array >>> end if >>> End if > > If you convert a VB6 project that contains control arrays to VB.NET using
the upgrade wizard, it will add code that simulates control arrays using some VB6-backward-compatibility classes. Look at that code to see how Microsoft does it. You can also just include the index number in the control name, and then access controls as Me.Controls("lblInformation" & indexNumber). ----- Tim Patrick Start-to-Finish Visual Basic 2005 Show quoteHide quote > In vb6 a group of controls ie command buttons could be refered to by > an index number ie cmdWord(4). This was accomplished by using the > index property of the control. Vb.net does not seem to have the index > property for buttons. Is there a way in vb.net to refer to a group of > controls in a way that includes a unique index number for the > specific control to be used? > > Thanks, > Howard Haisten Using Me.Controls("lblInformation" & IndexNumer) can cause a problem
when using obfuscating techniques. Tim Patrick wrote: Show quoteHide quote > If you convert a VB6 project that contains control arrays to VB.NET > using the upgrade wizard, it will add code that simulates control arrays > using some VB6-backward-compatibility classes. Look at that code to see > how Microsoft does it. You can also just include the index number in the > control name, and then access controls as Me.Controls("lblInformation" & > indexNumber). > > ----- > Tim Patrick > Start-to-Finish Visual Basic 2005 > >> In vb6 a group of controls ie command buttons could be refered to by >> an index number ie cmdWord(4). This was accomplished by using the >> index property of the control. Vb.net does not seem to have the index >> property for buttons. Is there a way in vb.net to refer to a group of >> controls in a way that includes a unique index number for the >> specific control to be used? >> >> Thanks, >> Howard Haisten > > That's true. Personally, I have stopped using control array-type code in
my VB.NET applications, choosing to give unique names to each control. I can bulk up your code a bit, although it is easy to use a common event handler for all of the related controls. For those situations where it might make sense to have a lot of controls with related logic, I try to find other means. For instance, I implemented a simple numeric keypad. My processing needs were met by using a common Click event, and using the Text (or Tag) property of the control to complete my processing. In other cases, I have migrated the independent controls to an owner-draw list box or grid control, which turned out better anyway. ----- Tim Patrick Start-to-Finish Visual Basic 2005 Show quoteHide quote > Using Me.Controls("lblInformation" & IndexNumer) can cause a problem > when using obfuscating techniques. > > Tim Patrick wrote: > >> If you convert a VB6 project that contains control arrays to VB.NET >> using the upgrade wizard, it will add code that simulates control >> arrays using some VB6-backward-compatibility classes. Look at that >> code to see how Microsoft does it. You can also just include the >> index number in the control name, and then access controls as >> Me.Controls("lblInformation" & indexNumber). >> >> ----- >> Tim Patrick >> Start-to-Finish Visual Basic 2005 >>> In vb6 a group of controls ie command buttons could be refered to by >>> an index number ie cmdWord(4). This was accomplished by using the >>> index property of the control. Vb.net does not seem to have the >>> index property for buttons. Is there a way in vb.net to refer to a >>> group of controls in a way that includes a unique index number for >>> the specific control to be used? >>> >>> Thanks, >>> Howard Haisten <jax1***@yahoo.com> schrieb:
> In vb6 a group of controls ie command buttons could be refered to by Accessing controls by their names or indices> an index number ie cmdWord(4). This was accomplished by using the > index property of the control. Vb.net does not seem to have the index > property for buttons. Is there a way in vb.net to refer to a group of > controls in a way that includes a unique index number for the > specific control to be used? <URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> On Fri, 27 Oct 2006 11:57:49 -0400, jax1***@yahoo.com wrote:
Thank you for your responses. I appreciate your help very much. Perhaps as I gain more and more knowledge and skill will vb.net I'll be able to be of assistance to someone else one day. I went with the suggestion from Cor Lightert. It worked very well !! Thanks again Howard Haisten Show quoteHide quote >In vb6 a group of controls ie command buttons could be refered to by >an index number ie cmdWord(4). This was accomplished by using the >index property of the control. Vb.net does not seem to have the index >property for buttons. Is there a way in vb.net to refer to a group of >controls in a way that includes a unique index number for the >specific control to be used? > >Thanks, >Howard Haisten
Adding Lines to Access Database
Merging two VB.NET projects Asynchronous Socket Server Question how to put two textboxes under each other? Detecting textchanged event when user initiates it where should the client app write the xml file to? Creating a new database with limits using SMO How to Reference a .Net Assembly from within VBA? Communicate with parallel port via web interphace Starting field on a form |
|||||||||||||||||||||||