Software Technology Tips

Tablelayoutpanel can arrange the controls in the cells by defining the column and row number. We can add controls by defining the column and row Number.

Add a TableLayoutPanel control in the form and name it as "TablelayoutPnl".
Dim IDLbl As New Label
IDLbl.Name = "ID"
IDLbl.Size = New System.Drawing.Size(10, 17)
IDLbl.Text = "Test"               
Dim IDpos As New TableLayoutPanelCellPosition(0, 0)
TablelayoutPnl.SetCellPosition(IDLbl, IDpos)
Dim NameTxt As New TextBox
NameTxt.Size = New System.Drawing.Size(100, 17)
NameTxt.Text = "Test Data"
Dim NamePos As New TableLayoutPanelCellPosition(1, 0)
TablelayoutPnl.SetCellPosition(NameTxt, NamePos)
Here one label and text box will be created in the first row in the first and second cell respectively.TableLayoutPanelCellPosition takes two parameters column and row. we can increase the row number in a for...loop if we want to create more number of rows.
Fetching controls in TableLayoutPanel
Dim ctrlInLastRow(TablelayoutPnl.ColumnCount - 1) As Control
Dim IDLbl As New Label
Dim NameTxt As New TextBox
Dim IDStr As String = String.Empty
Dim NameStr As String = String.Empty
          For Each ctrl As Control In TablelayoutPnl.Controls
                Dim cell As TableLayoutPanelCellPosition = TablelayoutPnl.GetCellPosition(ctrl)
                If cell.Row = TablelayoutPnl.GetRow(ctrl) Then
                    ctrlInLastRow(cell.Column) = ctrl
                    Select Case cell.Column
                       Case 0
                        IDLbl = CType(ctrl, Label)
                        IDStr = IDLbl.Text
                       Case 2
                        NameTxt= CType(ctrl, TextBox)
                        NameStr = NameTxt.Text
                    End Select
                End If
Here we can get the created label and text box's values according to the cell in the TablelayoutPanel.

Related Tags:

VB.NET, TablelayoutPanel

Author: Soumya Patnaik


Let us Connect!

Awards and Achievements

Red Herringcolor DeloitteFast50 DB ZInnov1   Nascome  DB Stpi

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login