Home > Ask the Microsoft .Net Development Experts > Visual Basic .NET Questions & Answers > Getting multiple textboxes and comboboxes into two arrays
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

Getting multiple textboxes and comboboxes into two arrays

Samuel Colak EXPERT RESPONSE FROM: Samuel Colak

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 12 March 2003
I am trying to upgrade code from VB4 to VB.NET. I am a bit confused by the collection (I am used to an array). On a form, I have multiple textboxes and multiple comboboxes. What I want to do is get these into two arrays, (one for the textboxes and one for the comboboxes), and be able to access each control in the collection individually (i.e. to add items to a specific combobox). I am trying to access the form control collection.

For counter =0 to controls.Count to then assign the different textboxes and comboboxes to their collection, but I don't seem to be able to get this to work?

So how do I do it? Thank you for your help.


>
I can understand your bemusement to this issue. It took me a few weeks to work this out before finally getting to grips with all the changes.

To be honest though you are very close to a solution....

As you discovered, the form object contains a collection called 'CONTROLS,' and within this the property are the controls themselves. I would advise keeping the information in there and using it. The following code will do what I think you are after achieving:

        Dim x As Control
        For Each x In Me.Controls
            Select Case (x.GetType.ToString)
                Case "System.Windows.Forms.TextBox"
                    Dim y As TextBox = CType(x, TextBox)
                    MsgBox(y.Text)
                Case Else
                    ' Do nothing
            End Select
        Next

Note that I used the CTYPE function to change the generic object x,' which is of type CONTROL to the type that is desired (in this case a textbox). You should note that the case uses the fully qualified name of the type. So if you were to add comboboxes to this, then you would perhaps add the case "System.Windows.Forms.ComboBox." Hope that helps.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
VB.NET
Access VB .NET Windows control on client side
Converting floating values to byte form
Read data from parallel port
Converting EXE-files to VB components
Generating classes like we did in VB6
Manipulating text through VB.NET
Converting Windows applications to VB .NET
How to add a key to a listview item in VB.NET
Accessing .NET components from VBScript
How I can assign an untyped dataset to a typed dataset?

Visual Basic .NET
Access VB .NET Windows control on client side
Drop down list server control creates error message
Converting floating values to byte form
Datagrid issue: 'onselection' is not populating
Read data from parallel port
What is the use of these constructors?
Give me an ODBC connect, with SQL authentication
Converting EXE-files to VB components
Generating classes like we did in VB6
Manipulating text through VB.NET

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts