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:

                for (int i = 0; i < columns.Length; i++)
                    fpSpread.Sheets[0].ColumnHeader.Cells[0, i].Text = columnsIdea;
                    fpSpread.Sheets[0].ColumnsIdea.AllowAutoSort = true;
                    fpSpread.Sheets[0].ColumnsIdea.Locked = true;

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

     Any ideas?

     This is the code before the loop:

    fpSpread.ActiveSheet.AutoGenerateColumns = false;

    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;

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

    fpSpread.SelectionBlockOptions = SelectionBlockOptions.Rows;
    fpSpread.ActiveSheet.OperationMode = OperationMode.RowMode;
    fpSpread.ActiveSheet.RowHeader.Visible = false;

    fpSpread.ActiveSheet.Protect = true;           




  • 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, fpSpread.Sheets[0].DataAutoSizeColumns = false; worked great. I then added the following line (as left out in the example I included before)

    fpSpread.Sheets[0].ColumnHeader.ColumnsIdea.Width = 120

    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