Solved

For each in Me.Controls Part 2

Posted on 2006-07-17
10
553 Views
Last Modified: 2012-08-13
Chaosian, shall I, in my form_Load() do this:

        For Each ctrl As Control In Me.Controls
            If TypeOf (ctrl) Is Button Then
                myButtons.Add(ctrl.Name, Nothing)
            ElseIf TypeOf (ctrl) Is Label Then
                myLabels.Add(ctrl.Name, Nothing)
            End If
        Next

Something like that, to put all my controls in my Dictionnary tables
Not sure what to put in the value parameter also
0
Comment
Question by:PhilippeRenaud
  • 6
  • 2
  • 2
10 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17123179
Hi PhilippeRenaud,

the value parameter is what is displayed to the user.  Are myButtons and myLabels Hashtable?

Apresto
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17123193
It was a Dictionnary
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17123219
Im noob with HashTable and Dicotnnary actually.
I just gave points in part 1 for the Dictonnary example, i found it great but, I dont know in fact wich one is the Best for wich situation. anyway.
0
 
LVL 23

Expert Comment

by:apresto
ID: 17123268
could you give a link to the first question :o)
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17123296
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 17123343
Dictionary is the new type-safe implementation of the collections. You can only use Dictionary and the other generic classes in VS2005.

Your posted code is close... but you need to add the actual control.

For Each ctrl As Control In Me.Controls
            If TypeOf (ctrl) Is Button Then
                myButtons.Add(ctrl.Name, ctrl)
            ElseIf TypeOf (ctrl) Is Label Then
                myLabels.Add(ctrl.Name, ctrl)
            End If
        Next

This way, you'll get the control back as the value from the Dictionary.

Note: trying to put anything other than a button in a Dictionary(of string, button) won't work... you were right to use a separate dictionary for labels.
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17123439
Yes

I did :

    Dim myButtons As Dictionary(Of String, Button)
    Dim myLabels As Dictionary(Of String, Label)

Also, i am getting an error here:
myLabels.Add(ctrl.Name, ctrl)

not sure why, let me try again
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17123456
What is the error?
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17123615
ok it focus on the lign :  myLabels.Add(ctrl.Name, ctrl)

saying:

System.NullReferenceException was unhandled
  Object reference not set to an instance of an object.
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17124592
dont understand why
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

15 Experts available now in Live!

Get 1:1 Help Now