473,382 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

TablePanelLayout Help

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 TablePanelLayout 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 getControlfromPosition, but it just returns nothing everytime I try to use it.

My table layout code looks like this:

Expand|Select|Wrap|Line Numbers
  1. Public Function LoadFeaturesLayout(ByVal FeatureId As Integer) As Boolean
  2.         Dim dt As DataTable
  3.         Dim i As Integer
  4.         Dim text As String
  5.         Dim objType As String
  6.         Dim featureText As Label
  7.         Dim dRow As DataRow
  8.         Dim height As Single
  9.         Panel2.AutoScroll = True
  10.         'Gets the data to load into the table
  11.         dt = GetTableData(FeatureId).Tables(0)
  12.  
  13.         'Clears all data and style from panel
  14.         layFeaturesTable.Controls.Clear()
  15.         layFeaturesTable.RowStyles.Clear()
  16.  
  17.         'Set panel dimensions
  18.         layFeaturesTable.RowCount = dt.Rows.Count
  19.         layFeaturesTable.ColumnCount = 2
  20.  
  21.  
  22.         layFeaturesTable.AutoSize = True
  23.  
  24.         i = 0
  25.  
  26.         'Stop painting table at runtime, allows table to be defined before drawing
  27.         layFeaturesTable.SuspendLayout()
  28.  
  29.         For Each dRow In dt.Rows
  30.  
  31.             If Not IsNothing(dRow("FeatureText")) Then
  32.  
  33.                 'Set Rowstyle
  34.                 layFeaturesTable.RowStyles.Add(New RowStyle(SizeType.AutoSize))
  35.                 text = dRow("FeatureText").ToString
  36.                 objType = dRow("FeatureControl").ToString
  37.                 featureText = New Label
  38.                 featureText.Text = text
  39.                 featureText.Dock = DockStyle.Fill
  40.  
  41.                 Select Case objType
  42.                     Case "Panel"
  43.  
  44.                         featureText.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  45.                         layFeaturesTable.Controls.Add(featureText, 0, i)
  46.                         layFeaturesTable.SetColumnSpan(featureText, 2)
  47.  
  48.  
  49.                         Dim locSpecLab As New Label
  50.                         Dim locTestLab As New Label
  51.                         locSpecLab.AutoSize = True
  52.                         locSpecLab.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  53.                         locSpecLab.Name = "lblSpec"
  54.                         locSpecLab.Size = New System.Drawing.Size(101, 17)
  55.                         locSpecLab.Text = "Specification"
  56.  
  57.                         locTestLab.AutoSize = True
  58.                         locTestLab.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  59.                         locTestLab.Size = New System.Drawing.Size(75, 17)
  60.                         locTestLab.Text = "Test Item"
  61.  
  62.                         ' layFeaturesTable.RowStyles.Add(New RowStyle(SizeType.AutoSize))
  63.                         layFeaturesTable.Controls.Add(locTestLab, 0, i + 1)
  64.                         layFeaturesTable.Controls.Add(locSpecLab, 1, i + 1)
  65.                         i = i + 1
  66.                     Case "Text"
  67.                         Dim locText As New TextBox
  68.                         locText.Dock = DockStyle.Fill
  69.                         layFeaturesTable.Controls.Add(featureText, 0, i)
  70.                         layFeaturesTable.Controls.Add(locText, 1, i)
  71.                     Case "Boolean"
  72.                         Dim locBool As New ComboBox
  73.                         locBool.Dock = DockStyle.Fill
  74.                         Dim locArray() As String = New String(1) {}
  75.                         locArray(0) = "Yes"
  76.                         locArray(1) = "No"
  77.                         locBool.Items.AddRange(locArray)
  78.                         layFeaturesTable.Controls.Add(featureText, 0, i)
  79.                         layFeaturesTable.Controls.Add(locBool, 1, i)
  80.                 End Select
  81.                 i = i + 1
  82.             End If
  83.         Next
  84.  
  85.         If i <= layFeaturesTable.Controls.Count - 1 And Not i > layFeaturesTable.Controls.Count - 1 Then
  86.             layFeaturesTable.Height = layFeaturesTable.Controls(i).Location.Y
  87.         End If
  88.  
  89.  
  90.         'Add cell borders to the panel
  91.         layFeaturesTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single
  92.  
  93.         'Allow panel to be scrollable if too large for groupbox
  94.         layFeaturesTable.Visible = True
  95.         layFeaturesTable.AutoScroll = True
  96.  
  97.         'Paints table to form
  98.         layFeaturesTable.ResumeLayout()
  99.         layFeaturesTable.PerformLayout()
  100.         'Panel2.Height = layFeaturesTable.Height
  101.  
  102.     End Function
And I am trying to access the values with the following:
Expand|Select|Wrap|Line Numbers
  1. Public Function getControlValue(ByVal featId As Integer, ByVal col As Integer, ByVal row As Integer) As String
  2.         Dim locControl As Control
  3.         Try
  4.  
  5.             locControl = layFeaturesTable.GetControlFromPosition(col, row)
  6.         Catch ex As Exception
  7.  
  8.         End Try
  9.  
  10.         If IsNothing(locControl) Then
  11.             Return Nothing
  12.         Else
  13.             Return locControl.Text
  14.         End If
  15. End Function

Any Help would be greatly appreciated!
Jan 18 '10 #1
2 2315
Why not just use a datagridview? Looks like it probably would be better for what you're trying to do. Im not exactly sure what you're doing after getting the data, but you may be able to just find each textbox control on the form

Dim thisTxt As Textbox
For each thisTxt In TablelayoutPanel
'Something here to save the text, eg. TableAdapter.Insert(thisTxt.Text)
Next
Jan 20 '10 #2
Hi Thanks,

For your post, I actually gave up on this method, I wanted to stick with the tablelayoutpanel as I think it looks a hell of lot better than datagridview. All I did was that I created a reference to each control with an arraylist everytime I added a new item into the table. So it was easier to get access to each dynamically generated control. It works like a treat.

And to store all the variables I also used an arrayllist of string arrays, which holds the data for each individual table!

boyindie
Jan 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
10
by: Jacek Generowicz | last post by:
Where can I find concise, clear documentation describing what one has to do in order to enable Python's internal help to be able to provide descriptions of Python keywords ? I am in a situation...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.