Regarding a post I found here about VB6 control arrays pseudo-duplicated in .NET ... here's the link to that posting.
How to create Control Arrays in VB .NET
I am in need (or at least I'm thinking I'm needing) of a control array using labels. I started working on a form using panels to contain 49 labels each. After I finished the 1st panel, I copied and pasted it to make another then another and so on. On the first panel I named each label with a simple unique name Num1 for label1 Num2 for 2nd label and so on to Num49. I need each panels labels to have all the same names which of course can't work. All the copies I made enumerated the labels using default Label names. So I need a label control array to be able to change the labels forecolors and backcolors properties for each panel according to the text value in each label. Example: I will search a database for records where say column1 contains the value "1" then I want to change each label Num1 in each panel and reset the fore and back colors to highlight them from they rest of the number labels.(1 thru 49) No here's the kicker ... I need the array to be dynamic. I won't know how many panels will be needed until after the sql search on the Dbase is finished. Once I get the number of records for all hits for "1" in column1 I will need to Dim or ReDim the label array to accommodate the number of returned records. So for example say 20 records came back with "1" in column1, I would display 20 panels with the number "1" label in each panel highlighted from the rest of the number labels. Each labels text value is just the numbers from 1-49. This is just a simple example as I may be using more than one column in the search and highlighting more than just one number label. So I'm thinking this may not be possible. The answer given in the original posting I linked to above by Hans Passant was the one that caught my eye as being simple and easy to implement however I need it to be dynamic in that depending on how many records come back will determine how many panels will be needed and hence the size of the control array. I don't think I will be needing any event handling so that might make it much easier but there is the possibility that I might decide to have the user be able to click on a number label which would change the data to be displayed. ie. highlighting new labels with a refined search or a subset of the 1st search.
Any ideas ...can it be done ?
Here's the code snippet in Hans answer to create a control array of textboxes, the one without event handling. I liked this one cuz it was simple as easy.
Public Class Form1 Private OrderNumbers() As TextBox
Public Sub New()
InitializeComponent()
OrderNumbers = New TextBox() {TextBox1, TextBox2}
End Sub
End Class
Now can this be made to create x number of textboxes depending on how many records come back in my search. The items in the braces would have to be variables of some sort dependent on the number of array elements required ?
StringorIntegerin VB.NET then you know all you need to know to create and use an array of controls.TextBoxesbased on run-time data then that has nothing really to do with arrays. Put aTableLayoutPanelon you form and then loop through the data and, for each record, create aTextBoxand add it to the TLP. That said, you could simply use aDataGridViewand not have to create controls at all.