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 » Community » Newbie corner » GridCtrl - get width column
GridCtrl - get width column [message #57300] Thu, 01 July 2021 05:44 Go to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

assuming I set up a grid with the measures of the columns below, later what function should I call to get these measures?

( like an getWidth ???)


	gPr.AddColumn ( "Código", 50 );
	gPr.AddColumn ( "Descricao", 250 );



Thanks
Re: GridCtrl - get width column [message #57301 is a reply to message #57300] Thu, 01 July 2021 11:41 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

gPr.GetColumn(index).Width()
Re: GridCtrl - get width column [message #57302 is a reply to message #57301] Thu, 01 July 2021 14:23 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

it make sence but:

error: 'Width' is a private member of 'Upp::GridCtrl::ItemRect'


Re: GridCtrl - get width column [message #57304 is a reply to message #57302] Thu, 01 July 2021 21:44 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Right Smile But you can do this with:
grid.GetWidth(my_column_index) - grid.GetWidth(my_column_index - 1)

But be careful with the moment you're calling those functions. If you add columns with widths expressed as proportions then the actual pixel width is not set until first grid paint is made.
Don't really know what's your use case but you shouldn't be interested in column width's in most cases until you want to paint sth inside the cell. But then you need to provide your own Display implementation in which current width and other properties are available. So that's another story.
Re: GridCtrl - get width column [message #57305 is a reply to message #57304] Fri, 02 July 2021 04:41 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

my case had 14 columns and after that I added the names and initially set a ratio. As the names of some columns were partially visible, so I wanted to build an function to just load the application and at runtime better define the adjust aspect ratio to display the full names of the columns. Among the initial question, I also started to take a look at the sources. In addition to your good suggestion (because without it had no idea that the column displays accumulated width / grid.GetWidth(index) ). But it would be interesting who produced the sources also gradually document the GridCtrl to also clarify the differences for example between fixed_cols, total_cols and GetColumnCount() and mainly how use them!

So I also found grid.Header().GetColumnWidths() which returns a string with sizes delimited with whitespace. This is now easier although you also have to remove spaces and index as below. I'll just leave it registered here because it might be useful for other developers.


	LOG( " width by accumulated in column / fixed_cols / total_cols---------- " << EOL );
	
	for ( int i = gPr.fixed_cols; i <= gPr.total_cols; i++ )
	{	
  	  if(i>1)    
  	   LOG( "column " << gPr.GetColumnName(i-2).ToString() << ": " << (gPr.GetWidth (i) - gPr.GetWidth (i- 1)) << EOL);
	} 
	
	LOG(  " width by GetColumnWidths / GetColumnCount ----------- " << EOL);
	
        String s =  gPr.Header().GetColumnWidths();
	
	Vector<String> words = Split(s, [](int c) { return c == ':' || c == '\t' || c == ' ' || c == ',' || c == '.' ? 1 : 0; });
	Vector<String> vnome;
	for(const auto& r : words)
            vnome.Add( r );

	for ( int i = 0; i < gPr.GetColumnCount(); i++ )
	  LOG( gPr.GetColumnName(i).ToString() << " width: " << vnome[i] << " \n");



Thanks


Previous Topic: Ultimate++ vs Wxwidgets for desktop linux/windows/mac app
Next Topic: Linux Executable
Goto Forum:
  


Current Time: Sun Jun 23 09:44:57 CEST 2024

Total time taken to generate the page: 0.02216 seconds