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

Positioning AutoGenerated Edit and Delete columns

2 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 26 Jan 2009, 03:03 PM
I have placed a screen shot on my server to give someone a visual of my issue.
Click Here to View the ScreenShot

This is a grid displaying two levels of detail tables nested in the Masterview
Food Category
     |
     Food Sub Category
          | 
          Food Menu Items

I have the AutoGenerateDeleteColumn and AutoGenerateEditColumn properties set to "true".  My objective is to allow the user to insert/edit/delete at every level.

My questions are :
  1. How can I position the "Delete" and "Edit" columns of the SubCategory band (i.e. Luncheons) and the FoodMenuItem band (i.e. "Cattleman Prime Rib") to the right side of the grid like it's parent band "Food Category" (Brunch/Lunch)?
  2. How can I size those columns to match widths and align nicely on the right with center alignment like the top parent level?
  3. If the above questions don't address it, how can I avoid the added expansion in width that occurs when the command columns become visible?  As you can see the overall width of the page increases beyond the width of the top graphic (MasterPage).
  4. When the page first loads the Grid is contracted to show only the root elements as desired.  The "Add New Record" and "Refresh" options do not appear on top until the fist row of the RadGrid is expanded. Does anyone know why that may be?
  5. How can I assign a style to the top header area to show something entirely different?

    Thank you

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 27 Jan 2009, 11:45 AM
Hello Reid,

You can position the columns using the Swap method to reorder columns.
cs:
RadGrid1.MasterTableView.SwapColumns("AutoGeneratedEditColumn", "ColumnUniqueName"); 
RadGrid1.MasterTableView.SwapColumns("AutoGeneratedDeleteColumn", "ColumnUniqueName"); 

You can also refer to the following help document which explains on how to align columns one below the other in a hierarchial grid.
Aligning columns in each level of hierarchical grid
 
You can set a CssClass for the header style(MasterTableView) and assign styles in the CssClass as shown below:
aspx:
<telerik:RadGrid ID="RadGrid1" AutoGenerateDeleteColumn="true" AutoGenerateEditColumn="true"  DataSourceID="SqlDataSource1" runat="server" >   
            
     <MasterTableView  CommandItemDisplay="Top" HeaderStyle-CssClass="header"  DataSourceID="SqlDataSource1" > 

css:
.header 
    { 
      background-image:url('image') !important; 
        
    } 

Thanks
Princy.
0
Reid
Top achievements
Rank 2
answered on 27 Jan 2009, 02:54 PM
HI Princy,

This is still not working for me.  I have a few questions.

Why can you add a "GridEditCommand" column type to a GridTableview but not a "GridDeleteCommand" column type?  Why does Telerik not allow you to add a generic "Command" type column that allows you to set the "CommandName" property? 

I would prefer to add these generic "command" columns to every GridTableView that will utilize editing for the following reasons:

  • I could set thier visible properties at runtime to enforce security very easily.
  • You could neatly tuck insert/edit/delete/cancel columns to the right of each band (GridTableView).  With that said you could size and place them as needed in a conventional way.  You would be assured they *always* exist.  You could apply styles to the command columns more efficiently. 
  • You could control it all at the GridTableView level, right now "AutoGenerateEdit" and "AutoGenerateDelete" properties are only available at the root level.  This makes it very confusing to understand for me as to when the grid creates them.  For instance the code you provided to swap the columns is causing an exception no matter where I put it. 

    I am using a method like below to set the grid's security when the page loads.  My objective is to handle it here in one place.  The problem is that if I retrofit the SwapColumns calls in this method the last two foreach loops do *not* find the "AutoGenerated*Column" types in the foodSubCategoryView yet at runtime the "Delete" and "Edit" links appear on that view.
  •  private void SetGridSecurity()  
        {  
            GridTableView foodCategoryView = grdFoodMenuListing.MasterTableView;  
            GridTableView foodSubCategoryView = foodCategoryView.DetailTables[0];  
            GridTableView foodMenuItemView = foodSubCategoryView.DetailTables[0];  
            SystemUser activeSystemUser = GetActor();  
            bool commandVisible = (activeSystemUser != null) && (activeSystemUser.Validated);         
     
     
            if ( commandVisible )  
            {  
                foodSubCategoryView.CommandItemDisplay = GridCommandItemDisplay.Top;  
                foodCategoryView.CommandItemDisplay = GridCommandItemDisplay.Top;  
                foodMenuItemView.CommandItemDisplay = GridCommandItemDisplay.Top;  
     
                grdFoodMenuListing.AutoGenerateDeleteColumn = true;  
                grdFoodMenuListing.AutoGenerateEditColumn = true;  
     
               }  
            else 
            {              
                grdFoodMenuListing.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;  
                grdFoodMenuListing.AutoGenerateDeleteColumn = false;  
                grdFoodMenuListing.AutoGenerateEditColumn = false;  
            }  
     
     
            foreach ( GridColumn column in foodCategoryView.Columns )  
            {  
                if ( column.UniqueName.Contains("AutoGeneratedEditColumn") )  
                {  
                    column.Visible = commandVisible;  
                }  
            }  
     
            foreach ( GridColumn column in foodCategoryView.Columns )  
            {  
                if ( column.UniqueName.Contains("AutoGeneratedDeleteColumn") )  
                {  
                    column.Visible = commandVisible;  
                }  
            }  
     
            foreach ( GridColumn column in foodSubCategoryView.Columns )  
            {  
                if ( column.UniqueName.Contains("AutoGeneratedEditColumn") )  
                {  
                    column.Visible = commandVisible;  
                }  
     
                if ( column.UniqueName.Contains("AutoGeneratedDeleteColumn") )  
                {  
                    column.Visible = commandVisible;  
                }  
            }  
        } 

 

Tags
Grid
Asked by
Reid
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Reid
Top achievements
Rank 2
Share this question
or