This is a migrated thread and some comments may be shown as answers.

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

1 Answer 154 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pawz
Top achievements
Rank 1
Pawz asked on 30 Jan 2012, 02:38 AM

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;
           }
           
        }

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 01 Feb 2012, 12:02 PM
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).

Tags
GridView
Asked by
Pawz
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or