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?

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> BuildRouteGrid()


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Counter </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> CheckBox </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> FarPoint.Win.Spread.CellType.CheckBoxCellType


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> ComboBox </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> FarPoint.Win.Spread.CellType.ComboBoxCellType


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> sz </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.Drawing.Size


    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> frmRoute.fpsRoute


    .Height = 250


    .Width = 1000


    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> .ActiveSheet


    .ColumnCount = 5


    </FONT><FONT color=#008000 size=2>'grid headings

    </FONT><FONT size=2>

    .ColumnHeader.Columns(colRteOperationID).Label = </FONT><FONT color=#a31515 size=2>"Operation ID"

    </FONT><FONT size=2>

    .ColumnHeader.Columns(colRteOperationDesc).Label = </FONT><FONT color=#a31515 size=2>"Operation Description"

    </FONT><FONT size=2>

    .ColumnHeader.Columns(colRteInstructionID).Label = </FONT><FONT color=#a31515 size=2>"Instruction ID"

    </FONT><FONT size=2>

    .ColumnHeader.Columns(colRteInstruction).Label = </FONT><FONT color=#a31515 size=2>"Instruction Description"

    </FONT><FONT size=2>

    .ColumnHeader.Columns(colRteQCRequestFlag).Label = </FONT><FONT color=#a31515 size=2>"QC Request"

    </FONT><FONT size=2>

    .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


    </FONT><FONT color=#008000 size=2>'re-size the column widths

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> Counter = 0 </FONT><FONT color=#0000ff size=2>To</FONT><FONT size=2> .ColumnCount - 1


    sz = .GetPreferredCellSize(0, Counter)


    .Columns(Counter).Width = sz.Width


    </FONT><FONT color=#0000ff size=2>Next

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>With

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>With

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub

    </FONT>
  • Replied 8 September 2017, 12:49 pm EST

    Instead of using GetPreferredCellSize I would recommend using <span id="pagetitle">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?
    </span>
  • 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