Hi Forum,
I have been fighting with this code for a day now.
What I have done is am have created a table in VB.NET using the TablePanelLayou t object. I manage to the build the table perfectly and it looks how I want it too look.
I load the formatting and headings in from a CSV file which I query using OLEDB.
My table basically has the following format
---------------------------------------
| Titles | Controls |
-------------------------------------------
| Bit of Text | textbox control |
----------------------------------------
(Ignore formatting this page seems to destroy it- it simply two columns, with column 1 full of headings and column 2 full of Controls)
So this will allow the user to enter all there details into the VB.NET form like this. But I am having problems accessing the data that is entered into the forms, as there is no static textboxes, Comboboxes which are made, prior to compilation as I make a new instance of the controls at runtime depending on the setup of the table.
I have tried using getControlfromP osition, but it just returns nothing everytime I try to use it.
My table layout code looks like this:
And I am trying to access the values with the following:
Any Help would be greatly appreciated!
I have been fighting with this code for a day now.
What I have done is am have created a table in VB.NET using the TablePanelLayou t object. I manage to the build the table perfectly and it looks how I want it too look.
I load the formatting and headings in from a CSV file which I query using OLEDB.
My table basically has the following format
---------------------------------------
| Titles | Controls |
-------------------------------------------
| Bit of Text | textbox control |
----------------------------------------
(Ignore formatting this page seems to destroy it- it simply two columns, with column 1 full of headings and column 2 full of Controls)
So this will allow the user to enter all there details into the VB.NET form like this. But I am having problems accessing the data that is entered into the forms, as there is no static textboxes, Comboboxes which are made, prior to compilation as I make a new instance of the controls at runtime depending on the setup of the table.
I have tried using getControlfromP osition, but it just returns nothing everytime I try to use it.
My table layout code looks like this:
Code:
Public Function LoadFeaturesLayout(ByVal FeatureId As Integer) As Boolean
Dim dt As DataTable
Dim i As Integer
Dim text As String
Dim objType As String
Dim featureText As Label
Dim dRow As DataRow
Dim height As Single
Panel2.AutoScroll = True
'Gets the data to load into the table
dt = GetTableData(FeatureId).Tables(0)
'Clears all data and style from panel
layFeaturesTable.Controls.Clear()
layFeaturesTable.RowStyles.Clear()
'Set panel dimensions
layFeaturesTable.RowCount = dt.Rows.Count
layFeaturesTable.ColumnCount = 2
layFeaturesTable.AutoSize = True
i = 0
'Stop painting table at runtime, allows table to be defined before drawing
layFeaturesTable.SuspendLayout()
For Each dRow In dt.Rows
If Not IsNothing(dRow("FeatureText")) Then
'Set Rowstyle
layFeaturesTable.RowStyles.Add(New RowStyle(SizeType.AutoSize))
text = dRow("FeatureText").ToString
objType = dRow("FeatureControl").ToString
featureText = New Label
featureText.Text = text
featureText.Dock = DockStyle.Fill
Select Case objType
Case "Panel"
featureText.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
layFeaturesTable.Controls.Add(featureText, 0, i)
layFeaturesTable.SetColumnSpan(featureText, 2)
Dim locSpecLab As New Label
Dim locTestLab As New Label
locSpecLab.AutoSize = True
locSpecLab.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
locSpecLab.Name = "lblSpec"
locSpecLab.Size = New System.Drawing.Size(101, 17)
locSpecLab.Text = "Specification"
locTestLab.AutoSize = True
locTestLab.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
locTestLab.Size = New System.Drawing.Size(75, 17)
locTestLab.Text = "Test Item"
' layFeaturesTable.RowStyles.Add(New RowStyle(SizeType.AutoSize))
layFeaturesTable.Controls.Add(locTestLab, 0, i + 1)
layFeaturesTable.Controls.Add(locSpecLab, 1, i + 1)
i = i + 1
Case "Text"
Dim locText As New TextBox
locText.Dock = DockStyle.Fill
layFeaturesTable.Controls.Add(featureText, 0, i)
layFeaturesTable.Controls.Add(locText, 1, i)
Case "Boolean"
Dim locBool As New ComboBox
locBool.Dock = DockStyle.Fill
Dim locArray() As String = New String(1) {}
locArray(0) = "Yes"
locArray(1) = "No"
locBool.Items.AddRange(locArray)
layFeaturesTable.Controls.Add(featureText, 0, i)
layFeaturesTable.Controls.Add(locBool, 1, i)
End Select
i = i + 1
End If
Next
If i <= layFeaturesTable.Controls.Count - 1 And Not i > layFeaturesTable.Controls.Count - 1 Then
layFeaturesTable.Height = layFeaturesTable.Controls(i).Location.Y
End If
'Add cell borders to the panel
layFeaturesTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single
'Allow panel to be scrollable if too large for groupbox
layFeaturesTable.Visible = True
layFeaturesTable.AutoScroll = True
'Paints table to form
layFeaturesTable.ResumeLayout()
layFeaturesTable.PerformLayout()
'Panel2.Height = layFeaturesTable.Height
End Function
Code:
Public Function getControlValue(ByVal featId As Integer, ByVal col As Integer, ByVal row As Integer) As String
Dim locControl As Control
Try
locControl = layFeaturesTable.GetControlFromPosition(col, row)
Catch ex As Exception
End Try
If IsNothing(locControl) Then
Return Nothing
Else
Return locControl.Text
End If
End Function
Any Help would be greatly appreciated!
Comment