Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB 2005 Looping through ComboBoxes

Hi I am trying to loop through 200+ ComboBoxes on a form to
get their text value using an array.

I am using
Dim myControl As Object
For Each MyControl in Me.Controls
etc

The problem is that it is only seeing the button and text controls and not the comboboxes

Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hello murbro,

have you tried to check for the type of the control
----------------
' cycle through the controls on the form.
For I = 1 ToMe.Controls.Count - 1
  ' select only comboboxes controls to get data
  If ((TypeOfMe.Controls(I) Is ComboBox)) And (Me.Controls(I).Text <> "") Then
    'do something here
  End If
Next I
----------------

hope this helps a bit
bruintje
Avatar of Murray Brown

ASKER

Hi

I have used exactly that approach and for some reason it isn't seeing ComboBoxes. Oh I forgot to mention
that the comboBoxes are added at runtime, when the form is loaded.
It is only seeing the text boxes and buttons that were originally there.

Thanks
if they're added at runtime, do you keep any reference to them in a collection or something?
No. Fairly new to .net. How would you do that
well, you could read up on creating a collection of controls as a replacement for the vb6 control array here
source: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchCreatingControlArraysInVisualBasicNETVisualCNET.asp?_r=1

it contains a solution to build a class for using in your own project and creating and deleting your own runtime control collections
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much