Solved

loading controls vb.net

Posted on 2006-07-17
1
170 Views
Last Modified: 2012-05-05
I had a vb6 application I am trying to convert.

I had a form, with a control array with one element.

I load the form, then reproduce the controls as I need them.

In this case, they are either text boxes or select boxes.

So if I wanted, I would display 5 of them across.

        If lastStep = 0 Then
            ctrlInputForm1(lastStep).Left = startLeft
            ctrlInputForm1(lastStep).Top = startTop
        Else
            Load ctrlInputForm1(lastStep)
            ctrlInputForm1(lastStep).Left = currentLeft
            ctrlInputForm1(lastStep).Top = currentTop
        end if

All I had to do was load the control with "Load" and it would work.

How can I do this with vb.net?

I need to be able to load controls named "ctrlInputForm" on the fly,
and refer to them somehow, in this case a control array.
0
Comment
Question by:jackjohnson44
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17125448
The control array in this sense no longer exists in VB.Net...

The simplest solution would be to dynamically create new controls and add them to an ArrayList

    Private myTextBoxes As New ArrayList

    Private Sub Foo()
            Dim tb As New TextBox
            tb.Left = currentLeft
            tb.Top = currentTop
            myTextBoxes.Add(tb)
            Me.Controls.Add(tb)   ' or add it to whatever container you need such as "Panel1.Controls.Add(tb)"
    End Sub

You can check the number of items in the ArrayList using Count (or Length...I can't remember which) to determine how many items are already in the array list.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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