|
|
Comments and Discussions
|
|
 |

|
I wonder if anybody has met this problem.
i write serval functions to turn the cell into combo type for temporarily,such as
BOOL CZoneInfo::SetComboStyle(int nRow,int nCol)
{
if (!m_GridCtrl.SetCellType(nRow,nCol,RUNTIME_CLASS(CGridCellCombo)))
return FALSE;
return TRUE;
}
void CZoneInfo::SetDefaultCellStyle(int nRow,int nCol)
{
m_GridCtrl.SetCellType(nRow,nCol, RUNTIME_CLASS(CGridCell));
m_GridCtrl.SetItemText(nRow,nCol, _T("null"));
m_GridCtrl.SetItemState(nRow,nCol, m_GridCtrl.GetItemState(nRow,nCol) & ~GVIS_READONLY);
m_GridCtrl.Invalidate();
}
void CZoneInfo::SetReadonlyCell(int nRow,int nCol)
{
SetDefaultCellStyle(nRow,nCol);
m_GridCtrl.SetItemState(nRow,nCol, m_GridCtrl.GetItemState(nRow,nCol) & GVIS_READONLY);
}
void CZoneInfo::SetComboStrings(CStringArray& ay,int nRow,int nCol)
{
int nCnt = ay.GetSize();
ASSERT(nCnt>0);
m_GridCtrl.SetItemText(nRow,nCol,ay.GetAt(0));
CGridCellCombo* pCell = (CGridCellCombo*)m_GridCtrl.GetCell(nRow,nCol);
pCell->SetOptions(ay);
pCell->SetStyle(CBS_DROPDOWN);
}
void CZoneInfo::SetCombo(CStringArray& ay,int nRow,int nCol)
{
SetDefaultCellStyle(nRow,nCol);
if(!SetComboStyle(nRow,nCol))
return;
SetComboStrings(ay,nRow,nCol);
}
void CZoneInfo::SetCombo(CStringArray& ay,CCellID& cell)
{
SetCombo(ay,cell.row,cell.col);
}
then i use SetCombo in the function OnEditGrid to turn the cell i clicked into combo type,
GV_DISPINFO* pDisp = (GV_DISPINFO*)pNMHDR;
switch (pInfo->iColumn)
{
case COLUMN_CHANNEL_CHASS: for(i=0;i<sizeof(strCHASS)/sizeof(strCHASS[0]);i++)
ay.Add(strCHASS[i]);
SetCombo(ay,m_cell);
break;
}
void CZoneInfo::OnGridEndEdit(NMHDR *pNotifyStruct, LRESULT* pResult)
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
CString str = m_GridCtrl.GetItemText(pItem->iRow,pItem->iColumn);
SetDefaultCellStyle(pItem->iRow,pItem->iColumn);
m_GridCtrl.SetItemText(pItem->iRow,pItem->iColumn,str);
*pResult = 0;
}
void CZoneInfo::OnGridStartSelChange(NMHDR *pNotifyStruct, LRESULT* )
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
}
void CZoneInfo::OnGridEndSelChange(NMHDR *pNotifyStruct, LRESULT* )
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
}
something like this,and when i clicked this column , it shows the dropdown list,and i can choose the value;
and when i lost focus of this cell,it should be recover to a default text cell,as it was;
but if i choose the 1st value, the arrow of dropdown list still exists, it didn't disappear , and i looked up
to the GridCellCombo.cpp, to see if i could fix this out, and i failed,so i asked this.
And thanks for those who will leave a word here first.
|
|
|
|
|

|
Dear Chris,
Your titled work is definitely appreciated, and we team would remember it from now on, which helped a lot...
For your information, we're a microISV team, and use the control in a VC2005 project on courseware / data protection.
Should you have inquiry or some form of input, assistance, feel free let me know.
Best Regards
|
|
|
|

|
V2.27, in demo application, use function InsertColumn case bug
|
|
|
|

|
Hoping some smart CodeProject people can help me out.
We have been using the Grid Control in an application for a long time.
Running under Windows 7 and 8, we have a problem that text in the grid control cells gets clipped. When I check the font height is much less than the cell space I get from GetTextExtents() or GetCellExtents() minus twice the margin. If I step the font height down low enough then it displays OK, but otherwise the text seems to be positioned too low in the cell and gets truncated to point that it is illegible.
I would like to reduce font height low enough, but I have not figured out how to do this programmatically, except by providing a pixel margin between the font height and row height minus twice the margin. But the pixel margin is just a number that I picked out by trial and error, so I am hoping someone has more insight into this problem.
Here is the while loop control statement I am using,
while( ((iRowHeight - (2*iMargin)) < (lf.lfHeight + TEXT_TO_CELLHEIGHT_REQD_PIXEL_MARGIN)) && (lf.lfHeight > LFHEIGHT_MIN))
Thanks in advance,
Tom
|
|
|
|

|
How do you center an image within a cell?
I've tried:
GV_ITEM Item;
Item.mask = GVIF_IMAGE|GVIF_FORMAT;
Item.row = row;
Item.col = col;
Item.nFormat = DT_CENTER|DT_VCENTER;
m_gridCtrl.SetItem(&Item);
which doesn't seem to work.
Thanks
|
|
|
|

|
Ok - I understand now that the library doesn't support this feature and that I have to download the source code and add in a new class (class CGridCellImage : public CGridCell) that will do this...sigh.
|
|
|
|

|
We have a legacy MFC application with a large number of dialog boxes which use a very old commercial data table DLL which is not supported any more.
Instead of converting all these dialog boxes to MFC, I'm investigating to see if it's possible to use your MFC Grid Control in a DLL instead.
So I created a MFC application, created a dialog box resource with the Grid Control and used the standard "old-style" C-code to invoke the dialog box:
CGridCtrl *pGridCtrl = new CGridCtrl();
DLGPROC lpfnTestDlgProc = lpfnTestDlgProc = (DLGPROC) MakeProcInstance((FARPROC) TestDlgProc, hInst);
if (DialogBox(hInst, MAKEINTRESOURCE(IDD_TESTGRIDDLL1_DIALOG), hWnd, lpfnTestDlgProc) == -1)
MessageBox(hWnd, _T("Low Resources -- could not create Dialog Box"), NULL, MB_OK|MB_ICONSTOP|MB_TASKMODAL);
FreeProcInstance((FARPROC) lpfnTestDlgProc);
if (pGridCtrl != NULL)
delete pGridCtrl;
Is there any way I can subclass the control (maybe while handling WM_INITDIALOG?) so that the GridCtrl can receive messsages from the dialog box?
Thanks,
Edward Clements
|
|
|
|

|
I found a way to subclass the control by adding the following lines while handling WM_INITDIALOG
HWND hGridWnd = ::GetDlgItem(hDlg, IDC_GRID);
pGridCtrl->SubclassWindow(hGridWnd)
Is this the "correct" way to do this, or is there a "better" way?
Thanks,
Edward Clements
|
|
|
|

|
If you click in a CGridCellCheck cell next to the check box, the default in-place edit field pops up over the check box. The fix is simple. At the class declaration just add
virtual bool Edit (int nRow, int nCol, CRect rect, CPoint point, UINT nID, UINT nChar);
And create an empty implementation in the source file
bool CGridCellCheck::Edit (int , int , CRect , CPoint , UINT , UINT )
{
return false;
}
You may also want to get a notification about changing the check box state, or override user action in some cases. So I modified CGridCellCheck::OnClick's second part:
if (SendMessageToParent (cell.row, cell.col, GVN_BEGINLABELEDIT) >= 0)
{
if (GetCheckPlacement ().PtInRect (PointCellRelative))
{
m_bChecked = !m_bChecked;
GetGrid ()->InvalidateRect (m_Rect);
SendMessageToParent (cell.row, cell.col, GVN_ENDLABELEDIT);
}
}
Unfortunately the more relevant LVN_ITEMCHANGING and LVN_ITEMCHANGED notifications are already used up for GVN_SELCHANGING and GVN_SELCHANGED.
|
|
|
|

|
Chris,
Is there any actual documentation available (other than what's in the article) on using the GridControl?
The demo compiles & runs fine with VS2010, but when I add a Custom Control to my code with the MFCGridCtrl class, the dialog fails to display
I'm going to look closely through the Demo to see what I'm missing, but if a complete how-to exists, I'd sure like to look it over.
Steve
|
|
|
|

|
Steve/Chris,
I've the same problem (grid not displaying in VS10). Who'd have thought that something I started using back in 2003 would still be going strong. Shows what a great control this is.
|
|
|
|

|
I had issues with OnRButtonUp behavior especially when my grids had only fixed row.
Just after the initialization and before filling the grid.
If I did right click on the fixed row, the focus was set to a wrong cell.
Here is my modified version of the method :
void CGridCtrl::OnRButtonUp(UINT nFlags, CPoint point)
{
CWnd::OnRButtonUp(nFlags, point);
m_bRMouseButtonDown = FALSE;
CCellID FocusCell;
FocusCell = GetCellFromPt(point);
EndEditing(); // Auto-destroy any InPlaceEdit's
// If not a valid cell, pass -1 for row and column
if(!IsValid(FocusCell))
SendMessageToParent(-1, -1, NM_RCLICK);
else
{
SetFocusCell(-1,-1);
// LS 2012/10/06 - To get same behavior as on left click.
// Before when the grid was empty, the focus could be set on unexisting row.
if (FocusCell.row >= GetFixedRowCount() && FocusCell.col >= GetFixedColumnCount())
{
SetFocusCell(FocusCell.row, FocusCell.col);
}
//else
// SetFocusCell(-1, -1);
//SetFocusCell(__max(FocusCell.row, m_nFixedRows),
// __max(FocusCell.col, m_nFixedCols));
// tell the cell about it
CGridCellBase* pCell = GetCell(FocusCell.row, FocusCell.col);
if (pCell)
pCell->OnRClick( GetPointClicked( FocusCell.row, FocusCell.col, point) );
SendMessageToParent(FocusCell.row, FocusCell.col, NM_RCLICK);
}
}
|
|
|
|

|
This thing is great.
Can you provide a version of the control?
|
|
|
|

|
I have disabled drag and drop by setting m_bAllowDragAndDrop to FALSE.
But unfortunately OnMouseMove ignores this setting in some situations and sets m_MouseMode to MOUSE_PREPARE_DRAG, which leads to undesired effects in OnLButtonUp which also ignores m_bAllowDragAndDrop when evaluating and handling m_MouseMode.
The code in OnLButtonUp obviously relies on m_MouseMode being set correctly, so OnMouseMove should have the same logic as OnLButtonDown, which checks m_bAllowDragAndDrop before setting m_MouseMode to MOUSE_PREPARE_DRAG.
By the way: in my opinion OnMouseMove should not switch m_nMouseMode from MOUSE_PREPARE_EDIT to MOUSE_PREPARE_DRAG, if the mouse has not been moved since the OnLButtonDown-Event.
I suggest the following fix that solves both issues:
void CGridCtrl::OnMouseMove(UINT , CPoint point)
{
...
#ifndef GRIDCONTROL_NO_DRAGDROP
case MOUSE_PREPARE_EDIT:
if (!m_bAllowDragAndDrop || m_LeftClickDownPoint == point) break; case MOUSE_PREPARE_DRAG:
m_MouseMode = MOUSE_PREPARE_DRAG;
OnBeginDrag();
break;
#endif
}
}
m_LastMousePoint = point;
}
Thomas Haase
|
|
|
|

|
Chris -
The file GridCtrl.cpp is missing a "/" in line 7. Line is "/" and should be "//".
|
|
|
|
|

|
I used the virtual mode.when i deal with GVN_ODCACHEHINT message ,i alway get the range of(-1,-1,-1,-1) .why? does this kind of messsage has special meaning?
|
|
|
|

|
is CGridCellCombo possible AutoCompletion ?
|
|
|
|

|
Hi! Chris,
I want to use your MFC Grid Control on VC++ 2010 but every time I try, I get the following error message:
Error 4 error LNK1120: 2 unresolved externals
error LNK2001: unresolved external symbol "public: __thiscall CGridCtrl::CGridCtrl(int,int,int,int)" (??0CGridCtrl@@QAE@HHHH@Z)
error LNK2001: unresolved external symbol "public: virtual __thiscall CGridCtrl::~CGridCtrl(void)" (??1CGridCtrl@@UAE@XZ)
Ironically, the demo project runs just fine. Please help me, what am I missing?
Thanks
Konark Uppal
|
|
|
|

|
Dear Mr Maunder,
I have a question regarding MFC-Grid-Control 2.25. I use it in a program for data aggregation in which it does excellent work. Now, I think of distributing my program open source.
In order to have optimal results, I have slightly modified some of your .cpp-files and .h-files. Would it be o.k. for you when I distribute your files together with the source code of my program with a hint that I did some slight modifications?
Thanks in advance.
Best regards,
Albert
|
|
|
|

|
That's fine.
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|
|

|
Dear Chris,
I am not quite sure whether I remember all changes I have made. Is it suffient to place a statement at the beginning of each file saying *that* I did some minor changes?
Or could you give me an original copy of vers. 2.25 such that I can find out what changes exactly I did?
Thanks in advance,
Albert
|
|
|
|
|

|
After upgrading to the most current version of the grid ctrl, I noticed that the top and bottom pixel of my cells were getting clipped off.
I tracked this back to the change made by Yogurt in 2.25 to the CGridCtrl::Draw function:
Changing:
rect.DeflateRect(GetMargin(), GetMargin());
rect.right++;
rect.bottom++;
back to:
rect.DeflateRect(GetMargin(), 0);
seems to have resolved the issue.
Since there isn't any code comments as to why the changes were made, I'm not sure what he was trying to accomplish or what this might possibly also affect butI figured I would post this here in case anyone else runs into the same problem.
|
|
|
|

|
I agree with you. When 2.25 has become available, we have also reverted this 'changed by Yogurt' modification back to the 2.24 style.
Thomas Haase
|
|
|
|

|
Hi,
(We're talking about CGridCellBase::Draw, not the one you've mentioned.)
The second parameter to DeflateRect was given so that margins are properly handled in the vertical direction as well.
However, I've noticed PrintCell does not have the right++ and bottom++ operations. Can you check whether these lines cause your problem?
|
|
|
|

|
Chris, great work! I want to write a DB application based purely on WinAPI, your code could be of great help to me, though it's MFC based. Can I use your workarounds and ideas in my project?
And one more a thing. When I select multiple whole rows having spaces between them, press Ctrl+C and then paste into excel sheet, empty spaces between rows also copies! That's unlikely for me. You could add an option: copy empty spaces also or remove it in copied data. Or have I missed a thing?
|
|
|
|

|
When CGridCtrl is used e.g. on FormViews of a Visual Studio 2010 SP1 MFC tabbed application, there are redraw issues in the live preview in the Windows 7 task bar.
In the preview any inactive mdi child window displays black areas where the grid control resides. (Standard controls, that are placed on the form view draw themself correctly in the preview).
After some hard investigation, I figured out, that probably a WM_PRINTCLIENT message handler is missing.
So finally I have added this message to the message map and I have implemented a simple implementation of the message handler. This seems to fix this issue without any notable undesired side effect.
Any comments are welcome.
BEGIN_MESSAGE_MAP(CGridCtrl, CWnd)
...
ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
and the implementation as follows (very similar to CMFCPropertyGridCtrl::OnPrintClient in afxpropertygridctrl.cpp)
LRESULT CGridCtrl::OnPrintClient(WPARAM wp, LPARAM lp)
{
DWORD dwFlags = (DWORD)lp;
if (dwFlags & PRF_ERASEBKGND)
{
SendMessage(WM_ERASEBKGND, wp);
}
if (dwFlags & PRF_CLIENT)
{
CDC* pDC = CDC::FromHandle((HDC)wp);
ASSERT_VALID(pDC);
OnDraw(pDC);
}
return 0;
}
/
Thomas Haase
|
|
|
|

|
Please forgive my ignorance; I am not a deep windows developer. I build my apps upon the brilliantly constructed building blocks graciously provided by others.
I'd like to be able to programmatically scroll the grid control vertically so that a programmatically selected range of cells is visible. I've tried both SetScrollPos and SetScrollInfo methods inherited from MFC controls. SetScrollInfo seems to do nothing. SetScrollPos( SB_VERT , iSetScrollPos , TRUE ); correctly positions the vertical scroll bar.... but the actual position of the grid cells doesn't update until I click on the vertical scroll bar -- at which point the control updates instantly to display the selected region.
I've searched everything I can find and can't identify any previous discussion on this topic.
- ep
|
|
|
|

|
Either of these may be what you're looking for:
void EnsureVisible(CCellID &cell);
void EnsureVisible(int nRow, int nCol);
|
|
|
|

|
Hello
Is it possible to make grid like this with different size elements?
If yes, then how?
|
|
|
|

|
my application (SDI) Environmental description:
win7+vs2008 c++ Environmental ,use CGridCtrl in Regular MFC DLL or sdi formview ,
but release not display grid data and grid header can display .
debug mode all normal.
pls help me. thank you!
|
|
|
|

|
if using GV_ITEM Item,check mask .
|
|
|
|

|
now i can use cgridctrl to create a grid.
i want to save the grid after merger cells.
when i load,now i want the grid whick i do merger operation last time.
how can i do???
please help me, please
|
|
|
|

|
Typo:
1>d:\projects\common\gridctrl\gridctrl.cpp(7) : error C2059: syntax error : '/'
This is a problem in VS 2008 and higher, and only for those using ATL:
1>d:\projects\common\gridctrl\memdc.h(26) : error C2011: 'CMemDC' : 'class' type redefinition
1> c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcontrolbarutil.h(62) : see declaration of 'CMemDC'
Please rename CMemDC to something else, that fixes it.
Thanks.
|
|
|
|

|
CRuleMemDC (Keith Rule?)
bart
|
|
|
|
|

|
what's the use of 'InPlaceEdit.cpp'?
And the differents btween InPlaceEdit and OnDraw ?
|
|
|
|

|
Hi,
Can you please help me for code compilation on VS2010.
I have converted VS2008 code to VS2010.
I am facing following errors while compilation with VS2010.
<pre lang="vb">1>LINK : warning LNK4199: /DELAYLOAD:oleacc.dll ignored; no imports found from oleacc.dll
1>GridCtrl.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base12::_Orphan_all(void)" (__imp_?_Orphan_all@_Container_base12@std@@QAEXXZ) referenced in function "protected: void __thiscall std::vector<int,class std::allocator<int> >::_Tidy(void)" (?_Tidy@?$vector@HV?$allocator@H@std@@@std@@IAEXXZ)
1>GridCtrl.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct std::_Iterator_base12 * * __thiscall std::_Container_base12::_Getpfirst(void)const " (__imp_?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ) referenced in function "protected: void __thiscall std::vector<int,class std::allocator<int> >::_Orphan_range(int *,int *)const " (?_Orphan_range@?$vector@HV?$allocator@H@std@@@std@@IBEXPAH0@Z)
1>GridCtrl.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base12::~_Container_base12(void)" (__imp_??1_Container_base12@std@@QAE@XZ) referenced in function __unwindfunclet$??0?$_Vector_val@HV?$allocator@H@std@@@std@@QAE@V?$allocator@H@1@@Z$0
1>GridCtrl.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base12::_Container_base12(void)" (__imp_??0_Container_base12@std@@QAE@XZ) referenced in function "public: __thiscall std::_Vector_val<int,class std::allocator<int> >::_Vector_val<int,class std::allocator<int> >(class std::allocator<int>)" (??0?$_Vector_val@HV?$allocator@H@std@@@std@@QAE@V?$allocator@H@1@@Z)
1>GridCtrl.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z) referenced in function "protected: void __thiscall std::vector<int,class std::allocator<int> >::_Xlen(void)const " (?_Xlen@?$vector@HV?$allocator@H@std@@@std@@IBEXXZ)
1>.\Debug/GridCtrlDemo.exe : fatal error LNK1120: 5 unresolved externals
Thanks,
Pravin
modified 17-Jan-12 4:13am.
|
|
|
|
|

|
it is nice control
could it be used in 64 ver of Ms Access
Look at your eyes:
There is a developer behind every piece of code!
Eyes are too complex what about them!
|
|
|
|

|
If the grid control has only a two columns (one fixed) and less than 9 rows (1 fixed), calling CGridCtrl::DeleteAllItems() has no effect and the grid is not cleared. Has anyone else encountered this problem? I read through the first 30 messages but did not find any reference to this problem. Is this a bug? Any help greatly appreciated.
|
|
|
|

|
Is your grid in virtual mode?
|
|
|
|

|
No. I couldn't get virtual mode to work. My grid is embedded in an window derived from CDockablePane. It looks like this:
// in header VariableWnd.h
CGridCtrl m_wndVariableGrid;
// in implementation VariableWnd.cpp
// int CVariableWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) calls InitGrid()
//..
void CVariableWnd::InitGrid()
{
if (1)
{
CWaitCursor wait;
m_wndVariableGrid.SetEditable(TRUE);
m_wndVariableGrid.EnableDragAndDrop(TRUE);
//m_wndVariableGrid.SetVirtualMode(TRUE); // <= only blank spaces
// extensive coding from here to populate the grid
/..
Any help appreciated. Thanks.
Edit: Jan 06, 2012. Preceding the m_listCtrl.DeleteAllItems() with m_listCtrl.AutoFill() solves the problem. I have no clue why.
modified 6-Jan-12 13:27pm.
|
|
|
|

|
Dear Author,
This is a great tool, and I appreciate making it available. It looks like you haven't compiled it by turning off the DRAG and DROP deature. You may want to compile it once by turning off the DRAG and DROP, to fix some minor include issues.
Thanks,
Mathew Simon
|
|
|
|

|
Incorrect work with m_arColOrder in CGridCtrl class.
m_arColOrder is not changed in function InsertColumn(...).
Therefore m_arColOrder[col] may cause an exception, because length of the array m_arColOrder not increased after insertion column.
|
|
|
|

|
When targeting Windows XP or Windows 2000 the GridCell.cpp must modified and instead of
ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth);
must use
ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(int);
|
|
|
|

|
in a Regular MFC DLL fomview app it's ok ,
but no dll formview is not normal.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
A fully featured MFC grid control for displaying tabular data. The grid is a custom control derived from CWnd
| Type | Article |
| Licence | CPOL |
| First Posted | 16 Nov 1999 |
| Views | 3,867,948 |
| Downloads | 113,307 |
| Bookmarked | 1,134 times |
|
|