TableLayoutPanel in VB.Net 2005
-
I am trying to add a TableLayoutPanel (programatically). Here's what I have so far:
Private Sub drawTableLayoutPanel() Dim iColumns As Integer = uxColumnsTbar.Maximum ' Horizontal Trackbar Dim iRows As Integer = uxRowsTbar.Maximum ' Vertical Trackbar ' Dim oTLP As New TableLayoutPanel oTLP.Location = New Point(0, 0) oTLP.Size = New Size(500, 200) oTLP.AutoScroll = True oTLP.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink oTLP.GrowStyle = TableLayoutPanelGrowStyle.AddRows oTLP.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset ' oTLP.ColumnCount = iColumns For c As Integer = 0 To (iColumns - 1) oTLP.ColumnStyles(c).SizeType = SizeType.Absolute ' Errors HERE with c=0 oTLP.ColumnStyles(c).Width = (1 / iColumns) Next ' oTLP.RowCount = iRows For r As Integer = 0 To (iRows - 1) oTLP.RowStyles(r).SizeType = SizeType.Absolute oTLP.RowStyles(r).Height = (1 / iRows) Next ' oTLP.Update() End Sub
The error I get is:
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"Which collection are they referring to? iColumns=6 and iRows=4 - this has been verified. Thanks, Karen Nooobie to OOP and VB.Net 2005
-
I am trying to add a TableLayoutPanel (programatically). Here's what I have so far:
Private Sub drawTableLayoutPanel() Dim iColumns As Integer = uxColumnsTbar.Maximum ' Horizontal Trackbar Dim iRows As Integer = uxRowsTbar.Maximum ' Vertical Trackbar ' Dim oTLP As New TableLayoutPanel oTLP.Location = New Point(0, 0) oTLP.Size = New Size(500, 200) oTLP.AutoScroll = True oTLP.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink oTLP.GrowStyle = TableLayoutPanelGrowStyle.AddRows oTLP.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset ' oTLP.ColumnCount = iColumns For c As Integer = 0 To (iColumns - 1) oTLP.ColumnStyles(c).SizeType = SizeType.Absolute ' Errors HERE with c=0 oTLP.ColumnStyles(c).Width = (1 / iColumns) Next ' oTLP.RowCount = iRows For r As Integer = 0 To (iRows - 1) oTLP.RowStyles(r).SizeType = SizeType.Absolute oTLP.RowStyles(r).Height = (1 / iRows) Next ' oTLP.Update() End Sub
The error I get is:
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"Which collection are they referring to? iColumns=6 and iRows=4 - this has been verified. Thanks, Karen Nooobie to OOP and VB.Net 2005
Well, I've haven't used the TableLayoutPanel yet, but it looks like the TableLayoutPanel.ColumnStyles collection is empty. Just because you set the ColumnCount to whatever, doesn't mean that there are any ColumnStyle objects added to the ColumnStylesCollection your trying to index.
For c As Integer = 0 To (iColumns - 1)
Dim newColStyle = New ColumnStyle(SizeType.Absolute, 1/iColumns)
NextRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I am trying to add a TableLayoutPanel (programatically). Here's what I have so far:
Private Sub drawTableLayoutPanel() Dim iColumns As Integer = uxColumnsTbar.Maximum ' Horizontal Trackbar Dim iRows As Integer = uxRowsTbar.Maximum ' Vertical Trackbar ' Dim oTLP As New TableLayoutPanel oTLP.Location = New Point(0, 0) oTLP.Size = New Size(500, 200) oTLP.AutoScroll = True oTLP.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink oTLP.GrowStyle = TableLayoutPanelGrowStyle.AddRows oTLP.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset ' oTLP.ColumnCount = iColumns For c As Integer = 0 To (iColumns - 1) oTLP.ColumnStyles(c).SizeType = SizeType.Absolute ' Errors HERE with c=0 oTLP.ColumnStyles(c).Width = (1 / iColumns) Next ' oTLP.RowCount = iRows For r As Integer = 0 To (iRows - 1) oTLP.RowStyles(r).SizeType = SizeType.Absolute oTLP.RowStyles(r).Height = (1 / iRows) Next ' oTLP.Update() End Sub
The error I get is:
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"Which collection are they referring to? iColumns=6 and iRows=4 - this has been verified. Thanks, Karen Nooobie to OOP and VB.Net 2005