Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Fit cells exactly into CExtGridWnd's area Collapse All
Subject Author Date
Bart Kampers Aug 17, 2009 - 8:41 AM

Hello,


I want the cells in my CExtGridWnd to have widths so that they exactly fit in the grid’s area. I tried to use GetClientRect to find out the area width but this does not give the correct size. It seems that I alway have to distract 64 from this size whether the scrollbars are show or not.


What is the proper way to retrieve the grid area?


Thanks,


Bart.

Technical Support Aug 17, 2009 - 1:46 PM

The Prof-UIS grids controls support the proportional resizing feature for both columns and rows. We will explain you how to use this feature for columns of the CExtGridWnd control. First of all, you should disable horizontal scrolling in your grid control. This means you should use the __ESIS_STH_NONE style in invocation of the SiwModifyStyle() method - not an any other __ESIS_STH_*** style. Second, you should apply the __EGBS_BSE_EX_PROPORTIONAL_COLUMN_WIDTHS style with invocation of the method. The proportional column widths are stored in the top header cells. You should invoke the CExtGridCell::ExtentPercentSet() method of header cells at top to specify how the cells should be resized proportionally. The columns still support minimal/current/maximal widths in pixels. These widths can be set using the CExtGridCell::ExtentSet() method. So, you can set some initial widths in pixels. If all the minimal/current/maximal widths are equal, then column is not resized proportionally and it cannot be resized by user.

Bart Kampers Aug 18, 2009 - 9:33 AM

Thanks for your response. This already works very nice but I’d like it to be a little bit nicer ;)


I would like to resize colums as the data in the grid changes. All columns have to be as wide so the contents fit. The last column must stretch the free space.


I made an "UpdateColumnWidths" method which is called as soon as the data in the grid is updated. I messed around a bit with "BestFitColumn" but I did not manage to get it right.


So, what can I do to get this done?


 


Also, I noticed that "BestFitColumn" sometimes goes wrong when all rows in a column contains one character. 

Technical Support Aug 18, 2009 - 12:42 PM

It’s possible to use best fitting and proportional resizing at the same time. But we do not recommend you to do this. Both features will constantly try to resize columns in their own manner. Best fitting is better without proportional resizing. The CExtGridWnd::BestFitColumn() method can change widths of a data column, header column at left or at right depending on the nColType parameter. One invocation of the CExtGridWnd::BestFitColumn() method changes widths of one column only. The column number is specified int the nColNo parameter. This method measures widths of the column’s grid cells before change column widths. The bDoBestFitByOuterCells, bDoBestFitByInnerCells and bDoBestFitByVisibleRowRangeOnly flag parameters determine which grid cells should be measured. The bDoBestFitByOuterCells flag specifies whether header cells at top/bottom should be measured in the nColNo column. The bDoBestFitByInnerCells flag specifies whether data cells should be measured and if this flag is true, then the bDoBestFitByVisibleRowRangeOnly flag determines whether only displayed on the screen data cells should be measured. If you want to make your grid automatically changing column widths after applying any editing results, then you should override the CExtGridWnd::OnGridCellInputComplete() virtual method, invoke parent class method from it and finally invoke the CExtGridWnd::BestFitColumn() method. If your code handles editing of some column’s cells and changes data in other columns, then you may need to invoke the CExtGridWnd::BestFitColumn() method for other columns too.