-
March 8th, 2011, 02:06 PM
#1
Dynamic Labels
Hi All
I am creating an electronic display board using Visual Studio 2005, this will be an application using VB and not web based.
What I am trying to do is use labels dynamicly and populate them from a dataset, Now there is a lot of labels on this board and to be honest the perfect solution would be to use a Data Grid View, unfortuantly I have to fit the information into a Custom Graphic that was created, hence the reason for labels.
So obvisouly I dont want to have to name each label and specify its information, for example:
Code:
Label1.text = MyDataSet.Tables(0).Rows(0).Item(0)
Label2.text = MyDataSet.Tables(0).Rows(1).Item(0)
Label3.text = MyDataSet.Tables(0).Rows(2).Item(0)
So I thought about something as follows but not sure how to get it work.
Say I new I had 100 Labels Label1 to Label100.
Code:
Dim i as Integer
For i = 1 to 100
Dim MyLabel as New Label
MyLabel.Name = "Label"& i
MyLabel.Text = MyDataSet.Tables(0).Rows(i).Item(0)
Next i
Now the above doesnt work but it doesnt throw up any errors either. So just looking for a little help to get me on the right path.
Edit *****
New Question..
I wasnt going to ask this because I know the rules regarding Key Loggers, but I am hoping there may be another way to do this without the Keylogging method. The electronic board will have multiple pages, I would like to be able to flick through the pages or go directly to the page using a Microsoft MCE remote control, Button 1 would take you to page 1, 2 to 2 ect. I know the remote control basically sends keystrokes directly to the focused application (I Think). Now 80% of the time there would not be an issue as the electronic board will have the focus, but our anti virus program (Trend Micro 10) seems to take focus for whatever reason.
If keylogging techniques are the only viable means then I appologise and please ignore this second question
*********
Cheers
Dougie
Last edited by 1druid1; March 8th, 2011 at 03:19 PM.
Reason: Extra Question
-
March 9th, 2011, 01:14 AM
#2
Re: Dynamic Labels
You have to provide more info when creating a new control. such as position and visible in order to get it to show on the screen,
Always use [code][/code] tags when posting code.
-
March 9th, 2011, 02:56 AM
#3
Re: Dynamic Labels
Hi
I am not trying to create new controls, I already have all my Labels on the form.
Cheers
-
March 9th, 2011, 05:12 AM
#4
Re: Dynamic Labels
Hi All
Think I have a solution for my first question
I have tried this and it works as longs as I set the tag to a number.
Code:
For Each ctl As Control In TabControl.TabPages.Item("TabPage4").Controls
If TypeOf ctl Is Label Then
Dim lbl As Label = DirectCast(ctl, Label)
If lbl.Name = ("LblP" & lbl.Tag) Then
lbl.Text = MyDataView.Table.Rows(lbl.Tag - 1).Item(0).ToString
ElseIf lbl.Name = ("LblR" & lbl.Tag) Then
lbl.Text = MyDataView.Table.Rows(lbl.Tag - 1).Item(3).ToString
End If
End If
Next
-
March 9th, 2011, 02:27 PM
#5
Re: Dynamic Labels
Originally Posted by 1druid1
Hi
I am not trying to create new controls, I already have all my Labels on the form.
Cheers
The code you posted is creating new labels, if that is not what you were trying to do then that would be part of the problem
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|