MFC Grid control with drop down lists
Download Source code and
demo project
This is a previous version of Chris Maunders MFC Grid control (version 1.03) with a minor bug fix and several improvements.
First a bug fix:
if ((nRow < m_nFixedRows)||(nCol < m_nFixedCols)) return;
And the improvements:
- I had the need to delete all rows but without the fixed rows and all the column attributes (see section 3), so I add function DeleteAllRows().
- I added an UINT array:
m_arColType
This array holds the Edit Type for each column. This Edit Type can take one of these values:
- GVET_NOEDIT (0x0000) cells in this column are not editable.
- GVET_EDITBOX(0x0001) cells in this column are editable in the old way (i.e. inplace Editbox is opened for the cell).
- GVET_LISTBOX (0x0002) cells in this column are editable in the way that an inplace Listbox is opened for the user to select value for this cell.
There are more styles (GVET_COMBOBOX, GVET_CHECKBOX) that are not implemented for now. (maybe someone would take the challenge to implement those styles before I do J).
- GVET_NOEDIT (0x0000) cells in this column are not editable.
- To set the Column Edit type Ive changed the InsertColumn() function to set this
attribute as well:
int InsertColumn(LPCTSTR strHeading, UINT nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE, int nColumn = -1, int nType = GVET_NOEDIT);
and I added the function:
BOOL SetColumnType(int nCol, int nType);
- To let the programmer to fill the inplace Listboxes Ive added virtual function:
virtual void FillListItems(int nCol, LPARAM cltList);
To use the Listbox cells attribute, you have to inherit your class from the
CGridCtrl and override the function : FillListItems. This function is called before
any inplace listbox is opened in order to fill its items by AddString. You can set
the user-defined data for each listbox item. This data is attached to the Grid items
user-defined data. (This is useful for lookup lists in the grid).
I would like to thank all the guys who contribute articles and code to this site and especially for Zafir Anjum and all the others who keeps this site so useful. I know I gain a lot of knowledge and save a lot of time by constantly visiting here.

Comments
How to add a Date/Time Edit in one column
Posted by Legacy on 07/16/2003 12:00amOriginally posted by: LoveisDark
I am new to c++, i like the code , but i want to add a date/Time edit column, how can i do? when dblclick , popup a windows Date/Time Dialog,where to find help?
Reply
How to sort contents in the grid columns
Posted by Legacy on 05/10/2003 12:00amOriginally posted by: Prashant
How to sort contents in the grid columns
Replyhow to merge cells?
Posted by Legacy on 07/16/2002 12:00amOriginally posted by: HTV
I don't know how to merge cells like VideoSoft Flex Grid
Replycrash after press enter
Posted by Legacy on 04/30/2002 12:00amOriginally posted by: xxx
crash after press enter after edit cell?why?
Reply
Implement checkbox
Posted by Legacy on 04/03/2001 12:00amOriginally posted by: Mike Wonder
How can I implement checkboxes?
Replywhy (OnFillList )does not take the row number??
Posted by Legacy on 02/18/2001 12:00amOriginally posted by: ahed bader
hi
Replyi want to make all one of the cell (in the list column)has its one data and take it from table
so... i need to now the row no. of the cell
so how
thenks;
ahed bader
gaza palistine
Why List Column be hide by the Custom Control
Posted by Legacy on 11/22/1999 12:00amOriginally posted by: NoTearsPIG
When i want to choice the last Item of the list column,
i found that it has been hided by the custom control.
ReplyWho can help me?
Drop Down with new Version (4.10.99)?
Posted by Legacy on 09/16/1999 12:00amOriginally posted by: Jean-Claude Demosthenidy
ReplyHaving a per-cell type would be incredible.
Posted by Legacy on 03/03/1999 12:00amOriginally posted by: Desperately seeking fix
ReplyDiable sorting at Drop Down Listbox..
Posted by Legacy on 02/19/1999 12:00amOriginally posted by: P. H. Kim
Hi,
Thanks to Motty Cohen.
If anyone doesn't want sorting at drop down listbox, Just remove some codes.
at InPlaceList.cpp
CHANGE
DWORD dwStyle2 = WS_BORDER|WS_CHILD|WS_VISIBLE|WS_VSCROLL|
CBS_DROPDOWNLIST|CBS_AUTOHSCROLL;
TO
DWORD dwStyle2 = WS_BORDER|WS_CHILD|WS_VISIBLE|WS_VSCROLL;
or simply make a function to change listbox property as you like.
Have a nice day~
ReplyLoading, Please Wait ...