|
|
Home » Community » Newbie corner » GridCtrl - get width column
GridCtrl - get width column [message #57300] |
Thu, 01 July 2021 05:44  |
BetoValle
Messages: 204 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 #57304 is a reply to message #57302] |
Thu, 01 July 2021 21:44   |
|
Right 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  |
BetoValle
Messages: 204 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
|
|
|
Goto Forum:
Current Time: Tue Apr 29 08:44:28 CEST 2025
Total time taken to generate the page: 0.00430 seconds
|
|
|