label control arrays

A

anthony

I know this is probably talk about millions of time here, but I cant seem
to find a close one, I am so used to the vb6 control array, now that I have
to use vb.net for my project, I like to do the following in vb.net with this
vb6 way:

In vb6, I would create five labels array on a form:
lblDisplay(1)...lblDisplay(5), and in each label I would have tag property:
Display1...Display5.

Then, in code (omitted some connection string below):

rst = new ADODB.Recordset
for i = 1 to lblDisplay.Count
rst.open("select Value from Tags where Name='" & lblDisplay(i).Tag &
"'")
lblDisplay(i).Caption = rst!Value
next i


How would I do this in VB.NET? I read some books, they mentioned about
using the Tag property to identify the control, but I want to get your
opinion on this.


Thanks!!!
 
G

Guest

This should get you started:

In the Load event of a form:

Dim LBL(5) As Label
Dim i As Int32
For i = 0 To 5
LBL(i) = New Label()
LBL(i).Top = i * 22
LBL(i).Text = "LBL" & i.ToString
Me.Controls.Add(LBL(i))
Next

You can use a Datatable instead of a Recordset as your data store.

The .Net Label has a Tag property.

www.charlesfarriersoftware.com
 
C

Cor Ligthert

Anthony,

Yes I have answered this often, however it is simple, create yourself that
array of labels and than you can use the code as you do. Using VBNet you can
put any control in an array and mixed exactly as you want.

dim myLblArr() as label = new label() {label1,label2,label3,label5,etc)

As question, is there any reason why you use ADODB, with that you have
forever to deploy as well the DLL, why not ADONET?

I hope this helps?

Cor

"anthony"
 
A

anthony

Thanks for your reply,

It looks like I have to create the label controls in run time.
 
A

anthony

Thanks,

Looks like I have to create the labels in run time, can it be done in design
time?

I used ADODB because I don't know much about ADONET, the project now didn't
allow me much time to research, but certainly now I will look at this in
depth.
 
C

Cor Ligthert

Anthony,

You don't have to create the labels in runtime.
Only that array I showed you, in another format.

dim myLblArr() as label = {label1,label2,label3,label5,etc}

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top