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 Tech Support » Changing colours of a CExtGridCellComboBox Collapse All
Subject Author Date
Darren Oliver Aug 28, 2007 - 12:40 PM

Hi Tech Support

I have a grid (class which inherits from CExtGridWnd) with many rows and columns. The cells inside the grid are either a CExtGridCellCheckBox or CExtGridCellComboBox. I wanted to have each cell the ability to change colour when invalid data was entered and switch back to the original colour when valid data was entered.

I tried to make a class which inherits from CExtGridCellComboBox and have that class hold the COLORREF of the original colour by calling BackColorGet() before changing the colour and using BackColorSet to change it to the invalid colour.

I am finding that I’m crashing when I call your method CExtGridWnd::RowRemoveAll(). What may be causing a problem is I iterate through each cell and retrieve it as a CExtGridCell to apply or remove the read-only style. The error I’m getting seems to vary but one is something like "invalid vtable pointer".

I may be approaching the colour changing the wrong way by inheriting from CExtGridCellComboBox and extending it with my colour codes and colour changing methods (which call your BackColorSet method) so any feedback is greatly appreciated.

Thanks,
Darren

Technical Support Aug 29, 2007 - 1:00 PM

The problem is not related to the color APIs. We guess you accessed a cell of some type when this cell is really of some other type. The methods of CExtGridWnd often use CExtGridCell* pointers. If you think that the returned CExtGridCell* pointer is really the CExtGridCellComboBox*</coded> pointer, then you should use the following code:

CExtGridCell * pSimpleCell = . . .
CExtGridCell * pComboBoxCell = STATIC_DOWNCAST( CExtGridCellComboBox, pSimpleCell );
The <code>STATIC_DOWNCAST preprocessor function will raise assertion if the pSimpleCell pointer is really not a CExtGridCellComboBox* pointer. Please do not use dirty casts in C style:
CExtGridCell * pComboBoxCell = (CExtGridCellComboBox*)pSimpleCell;

Suhai Gyorgy Aug 29, 2007 - 5:38 AM

If you derive a class from any CExtGridCell-derived class, and you add any additonal class variables, you need to override Assign method. In the background, there are many copying of the cells, and this Assign method assures that the proper values of your new class variables are stored in a new instance of cell.

You can see how it’s done in CompoundProperties sample, in the CMyCompoundFontCell class.

Also, you need to add an additional macro in your class definition: IMPLEMENT_ExtGridCell_Clone( CYourCell, CBaseCell );

You might also need to override the Serialize method if your cells get serialized at any point.