|
-
Jul 30th, 2007, 11:20 PM
#1
Thread Starter
Lively Member
[2005] Info on TableLayoutPanel
I use a listview to display tabular data where all I want is a 5 x 4 grid of text labels generated at runtime. I want to be able to control the font, row height, column width etc. The listview is working for me except for the height. Would I have been better off using the tablelayoutpanel? I can't find many code samples on the net.
-
Jul 30th, 2007, 11:48 PM
#2
Re: [2005] Info on TableLayoutPanel
The TableLayoutPanel would be the way to go. See lesson 9 here.
-
Jul 31st, 2007, 08:09 AM
#3
Re: [2005] Info on TableLayoutPanel
In addition to that video, if you haven't already downloaded the 101 Samples for VB 2005, you can do so here: http://msdn2.microsoft.com/en-us/vbasic/ms789075.aspx
Among all the great examples there is one using the TableLayoutPanel. Good luck.
-
Jul 31st, 2007, 10:09 AM
#4
Thread Starter
Lively Member
Re: [2005] Info on TableLayoutPanel
thanks.... i wish people had suggested this control when i originally posted in another thread which control was best..... this would have saved me a lot of time...
is it ok to create an instance of a control each time in a loop, add it to the tablelayoutpanel and use the same variable each time as i do below with label1 below:
Code:
For i = sourceIndex To sourceIndex + 19
If i >= sourceArray.Length Then
Exit For
Else
Dim label1 As New Label
label1.Text = sourceArray(i)
label1.TextAlign = ContentAlignment.MiddleCenter
label1.Font = My.Settings.myFont
label1.ForeColor = My.Settings.myForeColor
label1.BackColor = My.Settings.myBackColor
label1.AutoSize = True
Me.TableLayoutPanel1.Controls.Add(label1)
End If
Next
Also, where do the samples get their data from? Whenever I run them they are dataless..
Last edited by jeffnyc; Jul 31st, 2007 at 10:15 AM.
-
Jul 31st, 2007, 05:41 PM
#5
Re: [2005] Info on TableLayoutPanel
Yes, but that's not what you're doing. You are using a different variable each iteration of the loop because it's declared inside the loop. That variable is created and destroyed each iteration so it's a new variable each time. What you suggest is the appropriate way to do it, but this is how that would be implemented:
Code:
Dim label1 As Label
For i = sourceIndex To sourceIndex + 19
If i >= sourceArray.Length Then
Exit For
Else
label1 = New Label
label1.Text = sourceArray(i)
label1.TextAlign = ContentAlignment.MiddleCenter
label1.Font = My.Settings.myFont
label1.ForeColor = My.Settings.myForeColor
label1.BackColor = My.Settings.myBackColor
label1.AutoSize = True
Me.TableLayoutPanel1.Controls.Add(label1)
End If
Next
Now the variable is declared outside the loop so it truly is the same variable each time.
-
Jul 31st, 2007, 08:56 PM
#6
Thread Starter
Lively Member
Re: [2005] Info on TableLayoutPanel
 Originally Posted by jmcilhinney
Yes, but that's not what you're doing. You are using a different variable each iteration of the loop because it's declared inside the loop. That variable is created and destroyed each iteration so it's a new variable each time. What you suggest is the appropriate way to do it, but this is how that would be implemented:
Code:
Dim label1 As Label
For i = sourceIndex To sourceIndex + 19
If i >= sourceArray.Length Then
Exit For
Else
label1 = New Label
label1.Text = sourceArray(i)
label1.TextAlign = ContentAlignment.MiddleCenter
label1.Font = My.Settings.myFont
label1.ForeColor = My.Settings.myForeColor
label1.BackColor = My.Settings.myBackColor
label1.AutoSize = True
Me.TableLayoutPanel1.Controls.Add(label1)
End If
Next
Now the variable is declared outside the loop so it truly is the same variable each time.
Using this implementation, the only way to access the control subsequently is through the control collection of the tablelayout panel?
-
Jul 31st, 2007, 09:07 PM
#7
Re: [2005] Info on TableLayoutPanel
 Originally Posted by jeffnyc
Using this implementation, the only way to access the control subsequently is through the control collection of the tablelayout panel?
Yes, but that would be the case for any controls created at run time. Normally you would get a control from a TLP by its position, using the GetControlFromPosition method.
-
Aug 1st, 2007, 10:35 PM
#8
Thread Starter
Lively Member
Re: [2005] Info on TableLayoutPanel
 Originally Posted by jmcilhinney
Yes, but that would be the case for any controls created at run time. Normally you would get a control from a TLP by its position, using the GetControlFromPosition method.
So would both accomplish the same thing?
Code:
dim l as label
l = (Label)tlp1.GetControlFromPosition (0,0)
l.text = "Hello"
Code:
Me.tlp1.Controls(0).Text = "Hello"
Is one better? I'm guessing one reason is that with the later you have to know the one dimensional index, where as the former you can specify by row and column which is easier to conceptualize.
-
Aug 1st, 2007, 10:44 PM
#9
Re: [2005] Info on TableLayoutPanel
 Originally Posted by jeffnyc
I'm guessing one reason is that with the later you have to know the one dimensional index, where as the former you can specify by row and column which is easier to conceptualize.
Exactly. You use a TLP because you want a grid/tabular layout so that is the most logical way to treat the controls it contains.
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
|