Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Autosizing GridCtrl columns
Autosizing GridCtrl columns [message #38678] |
Fri, 04 January 2013 21:42 |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Hi,
I've been trying to make a function that will automatically size the columns in a GridCtrl based on their contents. So far I have
void CUtils::AutoSizeGrid(GridCtrl& grid)
{
intArray sizes;
sizes.SetCount(grid.GetColumnCount(),0);
int rows = grid.GetRowCount();
Font font = GetStdFont();
font.Bold();
for(int i=0;i<rows;i++)
{
for(int j=0;j<sizes.GetCount();j++)
{
String s = grid.Get(i,j).ToString();
Size sz = GetTextSize(s,font);
sizes[j] = max(sizes[j],sz.cx);
}
}
grid.Ready(false);
for(int j=0;j<sizes.GetCount();j++)
{
// grid.SetColWidth(j,sizes[j]);
grid.GetColumn(j).Width((5*sizes[j])/4);
}
grid.Ready(true);
}
but it seems that StdFont is not the right font and the fnt member of the column is private.
Obviously I think that GridCtrl should have an Autosize function (not setting) to do this on command but failing that, is there a good way to get the size of the column contents without deriving my own class from GridCtrl?
Thanks,
Nick
|
|
|
Goto Forum:
Current Time: Sat Jun 01 06:27:39 CEST 2024
Total time taken to generate the page: 0.00869 seconds
|