Solved

adding items to a listbox in a groupbox with radiobuttons vb 2008

Posted on 2009-05-03
2
567 Views
Last Modified: 2013-12-26
Hi,
I have a groupbox containing 3 listbox and 3 radio buttons, Im trying to write a function to add items to all 3 listbox, but I keep getting errors like Conversion from type 'RadioButton' to type 'String' is not valid type errors, is there a way to specify which control on the groupbox I want to work with?


Function ListBoxDefault(ByVal intSelected As Integer) As Integer
 

        For Each ctrl As ListBox In Me.GroupBox2.Controls
 

            ctrl.Items.Add(CStr("wwwww"))

             ctrl.Items.Add cstr("dddddd

        Next
 

    End Function
 

OR this
 
 

For Each listbox As String In Me.GroupBox2.Controls

            listbox.Insert(0, "wwww")
 

            

      Next

End Function

Open in new window

0
Comment
Question by:humberss
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24292519
With VB.Net 2008, you can specify that you only want a specific TYPE of control returned like this:

        For Each lb As ListBox In Me.GroupBox2.Controls.OfType(Of ListBox)()
            lb.Items.Add("wwwww")
            lb.Items.Add("ddddd")
        Next

0
 

Author Closing Comment

by:humberss
ID: 31577432
thanks for your quick response

Rod
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now