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

How to remove edit button in a hierarchical grid

2 Answers 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cecilie Nordbø
Top achievements
Rank 1
Cecilie Nordbø asked on 26 May 2011, 10:43 AM
Hi.
How can i remove edit button for a detailtable with in place mode in a hierarchical grid?
I have found a solution for a grid as follows:

   if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridDataInsertItem)
            {
                radGrid.MasterTableView.GetColumn(columnName).Visible = true;
                foreach (GridDataItem dataItem in radGrid.MasterTableView.Items)
                {
                    (dataItem[columnName].Controls[0]).Visible = false;
                }
            }
            else
                radGrid.MasterTableView.GetColumn(columnName).Visible = false;

but can't find out who to hide the edit button for the detailtable when i have a hierarchical grid with on detail table. Anyone?

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 May 2011, 12:21 PM
Hello Cecilie,

I am not quite sure about your requirement. I suppose you want  to hide the Edit column in DetailTable when one of the detail table row is in edit mode. If that is the requirement here is the code that I tried.

aspx:
<telerik:RadGrid runat="server" ID="RadGrid2">
   <MasterTableView DataKeyNames="CustomerID" EditMode="InPlace">
      <Columns>
        ....
</Columns>
         <DetailTables >
      <telerik:GridTableView Name="DetailTable1"
         </DetailTables >
   </MasterTableView>
</
telerik:RadGrid>


C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
 {
    if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "DetailTable1")
   {
      GridTableView detailTable = (GridTableView)e.Item.OwnerTableView;
      detailTable.GetColumn("AutoGeneratedEditColumn").Display = false;//here am using autogenerated edit column
 }
  }

Thanks,
Princy.
0
Cecilie Nordbø
Top achievements
Rank 1
answered on 26 May 2011, 01:18 PM
The requirement is right but e.Item is never of type GridEditableItem at the same time as e.Item.IsInEditMode = true. I found a solution from your suggestion. Thanks a lot Princy!

This will work:

   if (e.Item.OwnerTableView.Name == "DetailTable1" && e.Item is GridDataItem)
            {
                string columnName = "EditDistanceColumn";
                var detailTable = e.Item.OwnerTableView;
                if (e.Item.IsInEditMode && e.Item is GridDataInsertItem)
                    detailTable.GetColumn(columnName).Display = true;                
                else
                    detailTable.GetColumn(columnName).Display = false;
            }          
       
Tags
Grid
Asked by
Cecilie Nordbø
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Cecilie Nordbø
Top achievements
Rank 1
Share this question
or