|
Hi Chris,
I used your code recently in an MFC app and found it very useful while at the same time really simple to use and integrate. Thanks again for writing such cool code, I constantly learn from the many talented people like yourself who contribute code and articles at CodeProject,
cheers,
Daniel
|
|
|
|
|
Attached zip is empty - it has 0 bytes. Can you reupload the demo project?
|
|
|
|
|
I've updated the download to the latest zip. Sorry about that.
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|
|
I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized.
I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.
This is working fine :-
void CMainView::OnInitialUpdate() // CMainView is my application's default view
{
CFormView::OnInitialUpdate();
initialized = TRUE;
CWnd *pGridCtrl = GetDlgItem(IDC_SALEPURCHASEGRIDCTRL);
CRect rect,grid_rect;
CWnd *pWnd = this->GetOwner();
pWnd->GetClientRect(rect);
pGridCtrl->GetWindowRect(grid_rect); // works fine here
grid_rect = rect;
grid_rect.left += 16;
grid_rect.top += 150;
grid_rect.bottom -= 300;
grid_rect.right -= 16;
pGridCtrl->MoveWindow(grid_rect); // GridCtrl is resized properly
.
.
.
This is not working properly:-
void CMembersView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
initialized = TRUE;
CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
ASSERT(pGridCtrl); // Must exist
CRect rect,grid_rect;
CWnd *pWnd = this->GetOwner();
pWnd->GetClientRect(rect); // Also tried with &rect
pGridCtrl->GetWindowRect(grid_rect); // problem is here. no grid_rect coordinates
// grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect
grid_rect = rect;
grid_rect.left += 16;
grid_rect.top += 150;
grid_rect.bottom -= 300;
grid_rect.right -= 16;
pGridCtrl->MoveWindow(grid_rect); // Also tried with &grid_rect
.
.
.
---------------------------------------------
" Future Lies in Present "Manmohan Bishnoi
|
|
|
|
|
I follow the instruction, but get compile error. Who could tell me how to resolve this problem?
CTestGridView::OnInitialUpdate
{
CView::OnInitialUpdate();
if (m_pGrid == NULL)
{
m_pGrid = new CGridCtrl;
if (!m_pGrid ) return;
CRect rect;
GetClientRect(rect);
m_pGrid->Create(rect, this, 100);
...
...
}
}
Error 2 error C2512: 'CGridCtrl' : no appropriate default constructor available
Thanks for help!
|
|
|
|
|
I change the declaration of CGridCtrl in the header file, then it bulids OK.
change from
class CGridCtrl;
to
#include "Gridctrl.h"
|
|
|
|
|
------ Build started: Project: GridViewDemo, Configuration: Debug Win32 ------
Compiling...
StdAfx.cpp
WINVER not defined. Defaulting to 0x0600 (Windows Vista)
Compiling...
GridCell.cpp
GridCellBase.cpp
GridCtrl.cpp
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(425) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(425) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(425) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(426) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(1952) : error C2065: 'pos' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(1952) : error C2065: 'pos' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(1956) : error C2065: 'pos' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2214) : warning C4244: 'initializing' : conversion from 'ULONGLONG' to 'DWORD', possible loss of data
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2618) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2630) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2633) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2649) : error C2065: 'row' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2661) : error C2065: 'row' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2664) : error C2065: 'row' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2716) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2716) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2720) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2720) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2720) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2722) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2729) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2729) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2756) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2756) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2762) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2762) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2762) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2764) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2768) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(2768) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3192) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3192) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3192) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3194) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3194) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3195) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3196) : error C2065: 'j' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3246) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3246) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3246) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3249) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3249) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3250) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3251) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3412) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3412) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3412) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3416) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3416) : error C2065: 'col' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3490) : error C2668: 'CUIntArray::InsertAt' : ambiguous call to overloaded function
c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h(336): could be 'void CUIntArray::InsertAt(INT_PTR,CUIntArray *)'
c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h(333): or 'void CUIntArray::InsertAt(INT_PTR,UINT,INT_PTR)'
while trying to match the argument list '(int, int)'
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(3565) : error C2668: 'CUIntArray::InsertAt' : ambiguous call to overloaded function
c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h(336): could be 'void CUIntArray::InsertAt(INT_PTR,CUIntArray *)'
c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h(333): or 'void CUIntArray::InsertAt(INT_PTR,UINT,INT_PTR)'
while trying to match the argument list '(int, int)'
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4739) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4739) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4739) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4740) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4745) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4745) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4745) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4746) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4806) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4806) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4806) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4807) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4812) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4812) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4812) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(4813) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(6559) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(6559) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(6559) : error C2065: 'i' : undeclared identifier
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\gridctrl.cpp(6563) : error C2065: 'i' : undeclared identifier
GridDropTarget.cpp
InPlaceEdit.cpp
TitleTip.cpp
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\titletip.cpp(314) : error C2360: initialization of 'pts' is skipped by 'case' label
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\titletip.cpp(275) : see declaration of 'pts'
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\titletip.cpp(315) : error C2360: initialization of 'pts' is skipped by 'case' label
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_src\titletip.cpp(275) : see declaration of 'pts'
ChildFrm.cpp
GridViewDemo.cpp
c:\documents and settings\guru\pulpit\gridctrl_demo221\gridctrl_in_view\gridviewdemo.cpp(61) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.
c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(4818) : see declaration of 'CWinApp::Enable3dControls'
GridViewDemoDoc.cpp
GridViewDemoView.cpp
MainFrm.cpp
Generating Code...
Build log was saved at "file://C:\Documents and Settings\Guru\Pulpit\gridctrl_demo221\gridctrl_in_view\Debug\BuildLog.htm"
GridViewDemo - 72 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How to fix it? Please help...
|
|
|
|
|
I concur - the same error list at compile time from Visual Studio C++. This code is NOT designed for this compiler, but I cannot tell where it is supposed to work. If these incidental bugs are removed, the run-time is EVEN WORSE. This is a very pretty utility that I REALLY WANT, but it is wasting days of my time and yields nothing.
NOTICE: Please DO NOT USE this code!!!!!!!!!!!!!!! It does not work - stay very FAR AWAY....
|
|
|
|
|
The code works fine on the compiler it was built and tested on. I can only apologise that I've not had a chance to update it for newer compilers.
Please do a search on this site for 'Ultimate Grid' for a more up to date grid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
This is because of a VC++ properties for Loop.
go to Property Pages --> C/C++ --> Language --> Set No to "Force Conformance in For Loop Scope".
SHould Fix this Error.
|
|
|
|
|
|
Works perfectly for me. Can you retry?
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
It is refusing to work for me. Sorry
Could you email it?
I am trying to do a dummy MDI app in VS2005 because I have bigtime headaches with my proper app and the grid class not working after porting. I mention this elewhere in the other grid article.
Thanks.
|
|
|
|
|
hi~ i'm a begginer of vc++.
i just wany to create a small program.
so, i didn't use dialog and doc/view strucrture.
it seems not work on typical win32 application?
Thanks~
|
|
|
|
|
How to make the grid control transparent ?
Also if I have multiple grid controls on my View, how do I select more than one at a time ?
|
|
|
|
|
First of all, thanks for the great work!
While I tried to include the control in my own Dialog (as a custom control), my dialog did not appear anymore. It seems, I was not the first user facing this problem.
I found the solution in a user forum:
http://www.codeguru.com/forum/showthread.php?t=344824
I thought it may be worth posting this here, to save other guys' time...
Problem
-----------------------
1) created a solution with an MFC Application project (dialog based)
2) added a custom control to the dialog
3) Set the new control's class to MFCGridCtrl
4) Added all the .cpp and .h files for MFCGridCtrl files to the project
5) Placed #include "GridCtrl.h" in testDlg.cpp
6) Compiled
When run DoModal returns -1.
Investigating using debug the problem seems to be in:
dlgcore.cpp function CWnd::CreateDlgIndirect(..), just after AfxHookWindowCreate(this); (about line 315) there is:
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate, pParentWnd->GetSafeHwnd(), AfxDlgProc);
hWnd remains null after this call and the GetLastError that follows returns 0.
A little later hWnd is tested for null and if true some debug statements are shown then FALSE is returned.
Solution
------------------------------------
Re: about Custom Control
Thank you - exactly the answer that I had been searching for. the steps I took were:
1) moved '#include "GridCtrl.h"' from testDlg.cpp to testDlg.h
2) declared variable 'CGridCtrl m_gridCtrl' in testDlg.h
3) added 'DDX_GridControl(pDX, IDC_CUSTOM1, m_gridCtrl);' in DoDataExchange
4) Recompiled
...
Andy
|
|
|
|
|
It really work.
Thank u so much!
God bless kind-hearted guy!
|
|
|
|
|
Hi,
I did exactly the same.
1. Added Custom Control in Resource View via Toolbox
2. Set the control's class to MFCGridCtrl via PropertySheet
3. Added all the files to the project
4. Placed #include "GridCtrl.h" in *.h
5. declared variable CGridCtrl m_gridCtrl in *.h
6. added "DDX_GridControl(pDX, IDC_GRIDCTRL, m_gridCtrl);" in DoDataExchange
result of DoModal() is still -1. Without the custom control the dialog pops up.
Anybody has a clue?
|
|
|
|
|
Hi,
I add afx_msg void CMyView::OnContextMenu(.....), But it won't be called when I right click button on mouse. But the GridDemoDlg example works.
I noticed in CGridCtrl::OnRClick(), it call CWnd::OnRClick() which invokes OnContextMenu().
in the dialog demo example, CGridDemoDlg::OnContextMenu() is called, why won't work in the Doc/View example?
thanks
|
|
|
|
|
I have use'd Grid ctrl in a View .It worked.But I finded I can't set the Item unless the View is being actived.
I creat a function like this:
void CMyAppView::Filesave(CString path)
{
m_pGrid->SetItemText(0,0,"str");
AfxMessageBox("save");
}
When I called this function in CMyAppDoc.
The Msgbox is done.
But SetItemText doesn't work.
How can I do this problem?
|
|
|
|
|
Hi,
I am new to MFCs. So, I will appreciate any help in this regard.
I am using Chris Maunder's grid control. However, the horizontal scroll bar control (not the scroll box postion but the control postion) starts from the extreme left of the grid control application. How can I start the control from a specified (x,y) position. I need to have the control start from below column 1. Because, I will be placing another control beneath column0.
Please note, I am talking about the actual scroll bar control position and not the scroll box position itself.
Thank you!
vishwa
|
|
|
|
|
I want to load file text to grid using menu item as ID_FILE_OPEN. How can I do??
|
|
|
|
|
How can I use events like OnGridEndEdit or OnGridStartEdit or OnGridStartSelChange or OnGridEndSelChange when Text changes using it in a comboBox in view?
How can I use ComboBox events have a look of CBN_EDITCHAGE events?
Thanks in advance for your help
d
-- modified at 3:23 Monday 9th January, 2006
|
|
|
|
|
m_pGrid->Create(rect,this,100) except a critical error.
i think in mfc library CWnd::CreateEx(...
Why?
|
|
|
|
|
I asked this once before, but never got a response, so can someone please help me.
I have a CView that creates the CGridCtrl object, but my CView is not getting any messages like OnChar(). These are grabbed by the Grid Control and never passed up the chain.
How can I make this happen? I need to get these events in the CView.
|
|
|
|