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

Sizing GridButton Columns

4 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 22 Feb 2009, 10:46 PM
Hello,

I am using the ColumnCreated handler in a RadGrid to set the .ButtonType and Alignment of the Edit and Delete Autogenerated columns.  This is working but when I try to size the columns the alignment shifts left.

 protected void grdSponsoredLinks_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        // Set the LinkButtons to show as Edit / Delete icons instead 
        foreach ( GridColumn column in grdSponsoredLinks.MasterTableView.Columns ) 
        { 
            if ( column.ColumnType == "GridButtonColumn" ) 
            {                 
                (column as GridButtonColumn).ButtonType = GridButtonColumnType.ImageButton; 
              //  (column as GridButtonColumn).ItemStyle.Width = Unit.Point(C_DEFAULT_EDITCOMMAND_COLUMN_WIDTH);              
                (column as GridButtonColumn).ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
 
 
            } 
            if ( column.ColumnType == "GridEditCommandColumn" ) 
            { 
                (column as GridEditCommandColumn).ButtonType = GridButtonColumnType.ImageButton; 
                (column as GridEditCommandColumn).ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
            }             
        } 

If I uncomment out the line above the buttons align to the left.
Any suggestions would be welcomed.

Thanks

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Feb 2009, 07:01 AM
Hi Reid,

Try setting the width of the column in pixels and see whether it is working.

CS:
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        // Set the LinkButtons to show as Edit / Delete icons instead  
        foreach (GridColumn column in RadGrid1.MasterTableView.Columns) 
        { 
            if (column.ColumnType == "GridButtonColumn") 
            { 
                (column as GridButtonColumn).ButtonType = GridButtonColumnType.ImageButton; 
                (column as GridButtonColumn).ItemStyle.Width = Unit.Pixel(50);    
                (column as GridButtonColumn).ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
 
 
            } 
            if (column.ColumnType == "GridEditCommandColumn") 
            { 
                (column as GridEditCommandColumn).ButtonType = GridButtonColumnType.ImageButton; 
                (column as GridEditCommandColumn).ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
            } 
        }  
    } 

Shinu
0
Reid
Top achievements
Rank 2
answered on 23 Feb 2009, 02:08 PM
Hello Shinu,

I tried to size using Pixels as the unit of measurement instead of points and the result is the same.  And this is the same for either of the 3 grids I have on this page.  Again the columns do not resize and the alignment shifts left.

I wanted to mention that the grids are contained in PageViews.
0
Accepted
Daniel
Telerik team
answered on 24 Feb 2009, 07:35 AM
Hello Reid,

An alternative approach is shown below:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
  foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns) 
  { 
    if (column.UniqueName == "AutoGeneratedEditColumn" || column.UniqueName == "AutoGeneratedDeleteColumn"
    { 
      column.HeaderStyle.Width = Unit.Pixel(100); 
      column.ItemStyle.HorizontalAlign = HorizontalAlign.Right; 
    } 
  } 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Reid
Top achievements
Rank 2
answered on 24 Feb 2009, 01:55 PM
Hello Daniel and Shinu,

This solved it.  I believe there are two issues that needed addressing.

  1. Both the OnColumnCreated and OnPreRender event need to be deployed.
  2. The Column.HeaderStyle needs to be resized along with the Column itself.

Thank you

Tags
Grid
Asked by
Reid
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Reid
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or