Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
aaremke265
Edited 23-Nov-12 0:41am
v2
Comments
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
good
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)
      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.
  Permalink  
v3

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 472
1 sanket saxena 355
2 CPallini 205
3 thatraja 200
4 OriginalGriff 195
0 Sergey Alexandrovich Kryukov 8,784
1 OriginalGriff 5,025
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid