|
-
April 20th, 2010, 06:41 AM
#1
[RESOLVED] Dynamically remove row from table layout
Hi,
I have found multiple posts on the net stating that a row can be removed by using the following methods:
- decrement tableLayoutPanel.RowCount
- remove rowstyle: tableLayoutPanel.RowStyles.RemoveAt(...)
- remove corresponding controls of removed row in tabelLayoutPanel.Controls
- change RowCounter of controls that come after the removed row
Is there no simpler way?
Second question: Everytime a new row is created, a linklabel with the text "delete" appears on the last column of the new row. On clicking the linklabel the whole row is deleted. To delete the whole row I need to know which row the linklabel is on. How do I find out which linklabel has just been clicked? This is the function that creates my linklabel:
Code:
protected void CreateNewRow()
{
(...)
linklblRemove = new LinkLabel();
linklblRemove.Name = Convert.ToString(miRowNo); // Each linklbl has unique name
linklblRemove.Text = "Delete";
tblPnl.Controls.Add(linklblRemove, 3, miRowNo);
// Allows row to be removed on clicking linkLabel
linklblRemove.Click += new EventHandler(linklblRemove_Click);
}
This is the event handler:
Code:
protected void linklblRemove_Click(object sender, EventArgs e)
{
int liColumnNo = tblPnl.ColumnCount;
int liRowNo = Convert.ToInt32(linklblRemove.Name); // Name of linklabel equals row no
for (int i = 0; i < liColumnNo; i++)
{
tblPnl.GetControlFromPosition(i, liRowNo).Visible = false;
// OR tblPnl.Controls.RemoveAt(liIndexNo); WHERE int liIndexNo = liRowNo + liColumnNo;
}
}
-
April 28th, 2010, 09:56 AM
#2
Re: Dynamically remove row from table layout
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|