Results 1 to 6 of 6

Thread: How to get a Control cell row and column in TableLayoutPanel?

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: How to get a Control cell row and column in TableLayoutPanel?

    Right. I got here so far:
    Code:
    Public Class Form2
        Dim i As Integer = 0
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            'INCREMENT
            i += 1
            'MAKE GROWING ALL 50%
            TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
            'ADD A LABEL FOR INSTENCE
            TableLayoutPanel1.Controls.Add(New Label, TableLayoutPanel1.ColumnCount - 1, 0)
            'MANIPULATE ITS PROPERTIES
            TableLayoutPanel1.Controls.Item(TableLayoutPanel1.ColumnCount - 1).Text = i.ToString()
            TableLayoutPanel1.Controls.Item(TableLayoutPanel1.ColumnCount - 1).Dock = DockStyle.Top
        End Sub
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'MAKE TABLE GROW IN ROWS
            TableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddColumns
        End Sub
    End Class
    Questions:
    1) Why by pressing button1 (Incrementing a column filled with a label which contains current i value) make previous text string empty?
    2) Why I don't have access to other 'Label' properties? (Text orientation, Autosize, consider someone have a UserControl in it.)

    I might use wrong code structure but it still runs a bit. If I did, Please tell me where's my fault.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to get a Control cell row and column in TableLayoutPanel?

    Quote Originally Posted by pourkascheff View Post
    1) Why by pressing button1 (Incrementing a column filled with a label which contains current i value) make previous text string empty?
    I'm not really sure what you mean. Can you be specific about exactly what you expect to happen and exactly what does happen.
    Quote Originally Posted by pourkascheff View Post
    2) Why I don't have access to other 'Label' properties? (Text orientation, Autosize, consider someone have a UserControl in it.)
    The Controls collection can contain any type of control, so getting an item from it will return a Control reference. That means that you can only access members of the Control class via that reference. If you want to access members of a specific control type then you have to cast as that type. Obviously the object has to be that type or the cast will fail. If you know that the control is a specific type then you can use DirectCast. If you don't know whether it's that type or not then you can use TryCast.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width