Setting Column Header Width to size of the column text

Posted by: bzarnett on 8 September 2017, 1:32 pm EST

  • Posted 8 September 2017, 1:32 pm EST

    What parameters need to be set and code written so that the column headers are always the width of the associated column header text.

    In the current application, the same sheet is used and altered based on the users input. The columns for the sheet are assigned in an array and the processed as follows:

    <font face="courier new,courier">            for (int i = 0; i < columns.Length; i++)
                    fpSpread.Sheets[0].ColumnHeader.Cells[0, i].Text = columns<img src="/emoticons/emotion-55.gif" alt="Idea" />;
                    fpSpread.Sheets[0].Columns<img src="/emoticons/emotion-55.gif" alt="Idea" />.AllowAutoSort = true;
                    fpSpread.Sheets[0].Columns<img src="/emoticons/emotion-55.gif" alt="Idea" />.Locked = true;

    If I try and just set the column width, nothing happens.

     Any ideas?

     This is the code before the loop:

    <font face="courier new,courier">fpSpread.ActiveSheet.AutoGenerateColumns = false;

    </font><font face="courier new,courier">fpSpread.Sheets[0].DataAutoCellTypes = false;

    GridLine gl = new GridLine(FarPoint.Win.Spread.GridLineType.None, System.Drawing.Color.White);

    fpSpread.Sheets[0].HorizontalGridLine = gl;

    fpSpread.Sheets[0].VerticalGridLine = gl;</font>

    and this is the code after the loop (for reference)

    <font face="courier new,courier">fpSpread.SelectionBlockOptions = SelectionBlockOptions.Rows;
    fpSpread.ActiveSheet.OperationMode = OperationMode.RowMode;
    fpSpread.ActiveSheet.RowHeader.Visible = false;

    fpSpread.ActiveSheet.Protect = true;            </font>



  • Replied 8 September 2017, 1:32 pm EST


    What code are you using to set the width of the column? Is the Spread bound? If it is, make sure you are setting the DataAutoSizeColumns property is set to False, so you can programatically set the size.

  • Replied 8 September 2017, 1:32 pm EST

    Hi Scott,


    Thanks, <span style="font-size:10pt;font-family:'Courier New';">fpSpread.Sheets[0].DataAutoSizeColumns = <span style="color:blue;">false</span>; </span>worked great. I then added the following line (as left out in the example I included before)

    <span style="font-size:10pt;font-family:'Courier New';">fpSpread.Sheets[0].ColumnHeader.Columns<img src="/emoticons/emotion-55.gif" alt="Idea" />.Width = 120</span>

    Works great! Thanks.





Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels