Click here to Skip to main content
11,811,971 members (74,389 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB VB.NET
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
Edited 23-Nov-12 0:41am
TheOtherCPian at 23-Nov-12 8:33am
Which part are you having difficulty with, figuring out which controls to delete or deleting the controls?
Ezra Neil at 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
0 KrunalRohit 289
1 Abhinav S 215
2 Palash Mondal_ 210
3 CHill60 180
4 Sergey Alexandrovich Kryukov 130
0 OriginalGriff 3,893
1 KrunalRohit 2,441
2 CPallini 2,240
3 Maciej Los 2,155
4 ppolymorphe 1,725

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
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