CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010

    [RESOLVED] Dynamically remove row from table layout


    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:

    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:

    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;

  2. #2
    Join Date
    Jan 2010

    Re: Dynamically remove row from table layout

    I resolved it.

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

By using this site, you agree to the Privacy Policy