Dynamically creating controls with TableLayoutPanel Contrrols
-
Hi to all, I am trying to dynamically create label controls on TableLayoutPanel control, so that i have wrote following code. but at the debugging time it will genarate all the lables, but it doesnt show that panel as output. I checked its visible property its always false.... any body know why this happened? Public Sub fillTablePanel(ByVal ds As DataSet, ByVal TableName As String) FormContent.TablePanel.Parent = FormContent FormContent.TablePanel.Visible = True FormContent.TablePanel.BackColor = System.Drawing.SystemColors.ActiveCaptionText FormContent.TablePanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetPartial Dim tRows, tCols As Integer FormContent.TablePanel.ColumnCount = ds.Tables(TableName).Columns.Count For tCols = 0 To ds.Tables(TableName).Columns.Count - 1 FormContent.TablePanel.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100 / (ds.Tables(TableName).Columns.Count))) Next FormContent.TablePanel.RowCount = ds.Tables(TableName).Rows.Count For tRows = 0 To ds.Tables(TableName).Rows.Count - 1 FormContent.TablePanel.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100 / (ds.Tables(TableName).Rows.Count))) Next ReDim FormContent.lblHeader(ds.Tables(TableName).Columns.Count) For tCols = 0 To ds.Tables(TableName).Columns.Count - 1 FormContent.lblHeader(tCols) = New Label() FormContent.TablePanel.Controls.Add(FormContent.lblHeader(tCols), tCols, 0) FormContent.lblHeader(tCols).Text = Convert.ToString(ds.Tables(TableName).Columns.Item(tCols)) FormContent.lblHeader(tCols).Location = New Point(FormContent.TablePanel.Location.X, 10) FormContent.lblHeader(tCols).Visible = True FormContent.lblHeader(tCols).AutoSize = True Next FormContent.TablePanel.Location = New System.Drawing.Point(221, 46) FormContent.TablePanel.Name = "TablePanel" FormContent.TablePanel.RowCount = 2 Dim x As Integer = ds.Tables(TableName).Columns.Count Dim y As Integer = ds.Tables(TableName).Rows.Count ReDim FormContent.lblContent(x * y) Dim ctr As Integer = 0 For tRows = 0 To ds.Tables(TableName).Rows.Count - 1 For tCols = 0 To ds.Tables(TableName).Columns.Count - 1 FormContent.lblConten
-
Hi to all, I am trying to dynamically create label controls on TableLayoutPanel control, so that i have wrote following code. but at the debugging time it will genarate all the lables, but it doesnt show that panel as output. I checked its visible property its always false.... any body know why this happened? Public Sub fillTablePanel(ByVal ds As DataSet, ByVal TableName As String) FormContent.TablePanel.Parent = FormContent FormContent.TablePanel.Visible = True FormContent.TablePanel.BackColor = System.Drawing.SystemColors.ActiveCaptionText FormContent.TablePanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetPartial Dim tRows, tCols As Integer FormContent.TablePanel.ColumnCount = ds.Tables(TableName).Columns.Count For tCols = 0 To ds.Tables(TableName).Columns.Count - 1 FormContent.TablePanel.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100 / (ds.Tables(TableName).Columns.Count))) Next FormContent.TablePanel.RowCount = ds.Tables(TableName).Rows.Count For tRows = 0 To ds.Tables(TableName).Rows.Count - 1 FormContent.TablePanel.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100 / (ds.Tables(TableName).Rows.Count))) Next ReDim FormContent.lblHeader(ds.Tables(TableName).Columns.Count) For tCols = 0 To ds.Tables(TableName).Columns.Count - 1 FormContent.lblHeader(tCols) = New Label() FormContent.TablePanel.Controls.Add(FormContent.lblHeader(tCols), tCols, 0) FormContent.lblHeader(tCols).Text = Convert.ToString(ds.Tables(TableName).Columns.Item(tCols)) FormContent.lblHeader(tCols).Location = New Point(FormContent.TablePanel.Location.X, 10) FormContent.lblHeader(tCols).Visible = True FormContent.lblHeader(tCols).AutoSize = True Next FormContent.TablePanel.Location = New System.Drawing.Point(221, 46) FormContent.TablePanel.Name = "TablePanel" FormContent.TablePanel.RowCount = 2 Dim x As Integer = ds.Tables(TableName).Columns.Count Dim y As Integer = ds.Tables(TableName).Rows.Count ReDim FormContent.lblContent(x * y) Dim ctr As Integer = 0 For tRows = 0 To ds.Tables(TableName).Rows.Count - 1 For tCols = 0 To ds.Tables(TableName).Columns.Count - 1 FormContent.lblConten
I have only used the flowcontrol and in that case I created a user control for each set of data, placed all the management for the cotrol inside the user control and loaded 1 copy of the user control per record into the flowcontrol. That strategy may be relevant to the table control!
Never underestimate the power of human stupidity RAH