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 » CGridCtrl best practice for editing data Collapse All
Subject Author Date
Christophe Guibert Jun 26, 2006 - 4:07 PM

Hello,

I have a collection of objects, classicaly display their attribute members in a CGridCtrl (one object per row, one attribute per column), and I also would like to edit cell contents, be notified of the end of edition and store the changes in the correct attribute members of the correct objects that were used to populate the grid cells.

Subclassing CExtGridWnd class and overriding the virtual OnGridCellInputComplete() method gives the coordinates of any changed cell : however, user may have changed the column order or the row sort since the grid was initialized, and we get (wrong) coordinates that depend on the new order/sord of rows/columns that the application is not aware of.

Is there a preferred method to keep the origin of data so that we can easily propagate changes made to the grid into the objects ? For instance, in MFC CListCtrl, there are SetItemData()/GetItemData() methods. Is there a trick with the DataProvider object ? Do you have a sample ? (I guess this question is common, but did not find the answer in the forum, or missed something...).

Thanks in advance for your answer.

C. Guibert

Technical Support Jun 28, 2006 - 7:28 AM

Yes, to override the OnGridCellInputComplete() virtual method is the right way to handle the event when a cell gets changed. You are right that the user may change the column/row position and column/row sort order. So something needs to be done to identify a cell. You can easily done this by assigning some data to column/row headers and to cells. All the cell classes have the LParamSet and LParamGet parameters which allow you to assign some user data. So just use these parameters to mark all the cells and column/row headers.

Christophe Guibert Jun 28, 2006 - 2:59 PM

Hello,

Thank you for the prompt answer and for the tip : this works perfectly.

I have another question about GridCtrl : is it possible to serialize its current state (column widths and order) in order to retrieve it later as you did with the CExtReportGridWnd ?

An alternative for me would be to use the new CExtReportGridWnd : can we edit its cells and assign data (lParam) to its column headers ? Column/row headers seems to be managed differently and I guess that no data can be assigned to rows, but to inner cells.

Thanks a lot and Best Regards,

C. Guibert

Technical Support Jun 29, 2006 - 7:40 AM

Unfortunately this feature is not supported for CExtGridWnd. But actually it is not difficult to do yourself.

As for the second question, of course, you can assign user data to columns and rows. The CExtReportGridColumn class is derived from CExtGridCellHeader and the CExtReportGridItem class has CExtGridCell as one of the base classes. All the cell classes have the LParamSet and LParamGet parameters. This allows you to assign some user data. So just use these parameters to mark all the cells and column/row headers.

Christophe Guibert Jun 29, 2006 - 3:42 PM

Thank you for your answer : I’ll switch to CExtReportGridWnd.

Best Regards,

C. Guibert