Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Autosizing GridCtrl columns
Autosizing GridCtrl columns [message #38678] Fri, 04 January 2013 21:42
nixnixnix is currently offline  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



Previous Topic: ArrayCtrl vs GridCtrl
Next Topic: [maybe bug?] Removing last item in arrayctrl
Goto Forum:
  


Current Time: Thu Nov 21 19:43:03 CET 2019

Total time taken to generate the page: 0.01067 seconds