Click here to Skip to main content
13,139,114 members (59,690 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have one TableLayoutPanel (having one row, three columns) which is placed inside a Panel control on the form. My form also have one command button. Every time when the button is clicked a label (in first column), a textbox (in the second column), and a button (in the third column) will be created dynamically. I want to perform a operation like following:
When i click button (in third column of each row) then LABEL+TEXTBOX+BUTTON of concerned row must be deleted while leaving other controls as is. Could anybody help me out to resolve?
Posted 23-Nov-12 0:34am
Updated 23-Nov-12 0:41am
TheOtherCPian 23-Nov-12 8:33am
Which part are you having difficulty with, figuring out which controls to delete or deleting the controls?
Ezra Neil 5-Jan-13 1:57am
I don't get the downvote. If there is something wrong, it should be stated/discussed so I/we can do better.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The solution for this would be as follow

Private Sub Label1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Label1.Click
   Dim myTextBox As New TextBox
   Dim myButton As New Button
   AddHandler myButton.Click, AddressOf ButtonClick
   myTLP.Controls.Add(myTextBox, 1, 0)
   myTLP.Controls.Add(myButton, 2, 0)
End Sub
Private Sub ButtonClick(ByVal sender As Object, ByVal e As EventArgs)
   Dim tmpbtn As Button = TryCast(sender, Button)
   If Not tmpbtn Is Nothing Then
      For i As Integer = 0 To myTLP.ColumnCount - 1
         Dim tmpctr As Control = _
         myTLP.GetControlFromPosition(i, myTLP.GetRow(tmpbtn))
         If Not tmpctr Is Nothing Then myTLP.Controls.Remove(tmpctr)
   End If
End Sub

Add the same handler for each of the created button and it will delete accordingly.

Just make sure you set the ColumnCount and RowCount for the TableLayoutPanel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100