Solved

loading controls vb.net

Posted on 2006-07-17
1
167 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

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

18 Experts available now in Live!

Get 1:1 Help Now