How to remove a row from a child template using a GridCommandCellClick event

2 posts, 0 answers
  1. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 29 Jan 2012 Link to this post


    I'm trying to figure out how to remove rows from the child template of a on-demand loaded child. I can do this no problem with a standard command button on the Master template, but the child doesn't want to make the row go away.... 
    private void uiProductsGrid_CommandCellClick(object sender, EventArgs e)
            {
                GridCommandCellElement button = (GridCommandCellElement) sender;
     
                if (button.RowInfo.HierarchyLevel == 1)
               {
                   DataRowView drv = (DataRowView)button.RowInfo.DataBoundItem;
                   Guid id = (Guid)drv["Id"];
     
                   Selection.DeleteSelection(id);
                   button.MasterTemplate.Rows.Remove(button.RowInfo);
                   return;
               }
                if (button.RowInfo.HierarchyLevel ==2)
               {
                   Guid id = Guid.Parse(button.RowInfo.Cells["Id"].Value.ToString());
                   Product.DeleteProduct(id);
                    // What do I put here to remove this row from the grid???
                   return;
               }
               
            }
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 01 Feb 2012 Link to this post

    Hi Pawz,

    You can use the same approach that you are using for the rows at the first level. You can use the following code snippet as a sample:

    private void uiProductsGrid_CommandCellClick(object sender, EventArgs e)
    {
        GridCommandCellElement button = (GridCommandCellElement)sender;
        GridViewRowInfo row = button.RowInfo;
     
        if (row.HierarchyLevel == 1)
        {
            DataRowView drv = (DataRowView)row.DataBoundItem;
            Guid id = (Guid)drv["Id"];
            Selection.DeleteSelection(id);
        }
        else if (button.RowInfo.HierarchyLevel == 2)
        {
            Guid id = Guid.Parse(row.Cells["Id"].Value.ToString());
            Product.DeleteProduct(id);
            // What do I put here to remove this row from the grid???
        }
     
        row.Delete();
    }

    I hope this helps.

    Kind regards,
    Svett
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top