GetPreferredCellSize for only ColumnHeader

Posted by: jeremie-baldy on 8 September 2017, 2:38 pm EST

  • Posted 8 September 2017, 2:38 pm EST

    Hi !

    My environment:
    Windows 7 64 bit / i5 8 Go
    . Net 2.0
    Farpoint Spread WinForm 4.0.2026
    VS 2010

     I note:

                foreach (Column c in sheet.ColumnHeader.Columns)
                    c.Width = c.GetPreferredWidth();

    Is so long.... (with 23 000 rows... ~1 minute)

     

    I need to find best size for only ColumnHeader Cells.

    Is it possible ?

    sheet.GetPreferredCellSize(0, 0); -> Takes only sheet data, not Header Cells ?

     

    Thanks

     

  • Replied 8 September 2017, 2:38 pm EST

    The ColumnHeader Class has a Columns Property that returns a collection of Column Objects upon which you can call the GetPreferredWidth Method

  • Replied 8 September 2017, 2:38 pm EST

    paul1960:

    The ColumnHeader Class has a Columns Property that returns a collection of Column Objects upon which you can call the GetPreferredWidth Method

     

    Hum...

    In my first post i say:

                foreach (Column c in sheet.ColumnHeader.Columns)
                    c.Width = c.GetPreferredWidth();

    Is so long (surely it takes data sheet ~23 000 rows!)

     

    Your solution is different ?

     

     

    Otherwise this solution may be agree ?

                 foreach (Row r in sheet.ColumnHeader.Rows)
                {
                    foreach (Column c in sheet.ColumnHeader.Columns)
                    {
                        Cell cell = sheet.ColumnHeader.Cells[r.Index, c.Index];
                        Size s = TextRenderer.MeasureText(cell.Text, cell.Font);
                        if (sheet.Rows[r.Index].Height < s.Height)
                            sheet.Rows[r.Index].Height = s.Height;
                        if (sheet.Columns[c.Index].Width < s.Width)
                            sheet.Columns[c.Index].Width = s.Width;
                    }
                }

  • Replied 8 September 2017, 2:38 pm EST

    Your solution should work, I was thinking that there was a GetPreferredCellSize method for Cells but its actually a sheet method and won't work for a ColumnHeader Cell
Need extra support?

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

Learn More

Forum Channels