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

[Solved] Need to programatically set width of column - help please

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Denise Duggan
Top achievements
Rank 1
Denise Duggan asked on 03 Feb 2010, 09:12 PM
Because I don't know how many columns will be needed at design time, I've delved into programatically creating grid columns and adding them to the grid.  However, I cannot seem to affect the width of the column.  Could someone please help me understand how to set the width of the column?  If I were doing this in the markup I'd set the HeaderStyle and/or ItemStyle but those appear to be readonly properties when I view them in the codebehind.  Help?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2010, 08:46 AM
Hello Denise,

You can set the width of the column programatically as shown below:
c#:
        GridBoundColumn bndcol = new GridBoundColumn(); 
        bndcol.UniqueName = "FirstName"
        bndcol.HeaderText = "First Name"
        bndcol.DataField = "FirstName"
        bndcol.HeaderStyle.Width = Unit.Pixel(100); 
        this.RadGrid1.MasterTableView.TableLayout = GridTableLayout.Fixed; 
        this.RadGrid1.MasterTableView.Columns.Add(bndcol); 

Thanks
Shinu.
Tags
Grid
Asked by
Denise Duggan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or