Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 23-Nov-12 0:41am
v2
Comments
BotCar 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

The solution for this would be as follow

VB
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)
      Next
   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.
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900