resizing columns

Posted by: ginacresse on 8 September 2017, 12:49 pm EST

  • Posted 8 September 2017, 12:49 pm EST

    I'm using this code to build a simple grid.  It all worked fine until I tried to resize the columns. first I tried to resize only the first column, which is a combobox, and the combobox celltype seemed to disappear.  When I added the loop to resize all columns, 3 of the 5 columns disappear altogether.  What am I doing wrong?


    Public Sub BuildRouteGrid()


    Dim Counter As Short


    Dim CheckBox As New FarPoint.Win.Spread.CellType.CheckBoxCellType


    Dim ComboBox As New FarPoint.Win.Spread.CellType.ComboBoxCellType


    Dim sz As System.Drawing.Size


    With frmRoute.fpsRoute


    .Height = 250


    .Width = 1000


    With .ActiveSheet


    .ColumnCount = 5


    'grid headings


    .ColumnHeader.Columns(colRteOperationID).Label = "Operation ID"


    .ColumnHeader.Columns(colRteOperationDesc).Label = "Operation Description"


    .ColumnHeader.Columns(colRteInstructionID).Label = "Instruction ID"


    .ColumnHeader.Columns(colRteInstruction).Label = "Instruction Description"


    .ColumnHeader.Columns(colRteQCRequestFlag).Label = "QC Request"


    .Cells(0, 0, .RowCount - 1, 0).CellType = ComboBox


    .Cells(0, 4, .RowCount - 1, 4).CellType = CheckBox


    .Cells(0, 4, .RowCount - 1, 4).HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center


    're-size the column widths


    For Counter = 0 To .ColumnCount - 1


    sz = .GetPreferredCellSize(0, Counter)


    .Columns(Counter).Width = sz.Width


    Next


    End With


    End With


    End Sub

  • Replied 8 September 2017, 12:49 pm EST

    Instead of using GetPreferredCellSize I would recommend using GetPreferredColumnWidth, which will loop through all the cells and determine the optimum size for the column.  If that doesn't correct your issue can you post a small project reproducing this for us to debug?
  • Replied 8 September 2017, 12:49 pm EST

    Thanks.  GetPreferredColumnWidth was the answer.
Need extra support?

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

Learn More

Forum Channels