|
|
Comments and Discussions
|
|
 |

|
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.
|
|
|
|

|
The Is-functions in GridCellBase.cpp do not behave as expected, when checking their return value against TRUE.
Here is a small example, where bDummy never becomes TRUE.
BOOL bDummy = pCell->IsModified() == TRUE; // bDummy is never TRUE
This is because these functions return some non-zero values instead of TRUE. To fix this issue, when evaluating the mask, the result should be checked against zero, e.g. return 0 != (m_nState & ...).
virtual BOOL IsFocused() const { return 0 != (m_nState & GVIS_FOCUSED); }
virtual BOOL IsFixed() const { return 0 != (m_nState & GVIS_FIXED); }
virtual BOOL IsFixedCol() const { return 0 != (m_nState & GVIS_FIXEDCOL); }
virtual BOOL IsFixedRow() const { return 0 != (m_nState & GVIS_FIXEDROW); }
virtual BOOL IsSelected() const { return 0 != (m_nState & GVIS_SELECTED); }
virtual BOOL IsReadOnly() const { return 0 != (m_nState & GVIS_READONLY); }
virtual BOOL IsModified() const { return 0 != (m_nState & GVIS_MODIFIED); }
virtual BOOL IsDropHighlighted() const { return 0 != (m_nState & GVIS_DROPHILITED); }
Thomas Haase
|
|
|
|

|
You are not right.
BOOL is a typedef of int and BOOL != bool
Never compare with TRUE, only != FALSE because TRUE may not be 1
|
|
|
|

|
I don't know which version you are viewing. I have something different in my GridCellBase.h:
virtual bool IsFocused (void) const { return ((m_nState & GVIS_FOCUSED) == GVIS_FOCUSED); }
etc.
This is a more proper way of checking if the &'ed value is not a single bit. (For example 5 & 3 != 0 is true, even if bit 2 is not present in 5.)
(The BOOL -> bool conversion is mine.)
|
|
|
|

|
Hi Yogurt,
I'm referring to the official GridCtrlBase.h from the 2.27 package, which can be downloaded from this page.
Thomas Haase
|
|
|
|

|
When this grid is placed in a Regular MFC DLL dialog app, is run on Win 7 or vista, no problem,
but on Win XP Pro (Version 2002 / SvcPk 3), it fails to obtain proper grid sizing and Assert Violation occurs:
in GridCell.cpp
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));
and in Release config, the size is all wrong and the grid is dysfunctional. The same code runs just fine
when the grid is installed in a non-dll app. What gives with XPPro ?
|
|
|
|

|
Got the same problem, control does not work when use in a dll app.
|
|
|
|

|
My application like it.
release mode,some formview grid data not display ,but some formview can,
debug mode normal all.
above it run on win7.
run it on xp same as win7.
|
|
|
|

|
Hi community!
I try to expand last column to fit the rest of my control but this don't work!
Any idea how to fix tis?
Here is code from this function:
int nDifference = rect.Width() -(int) virtualWidth;
if (nDifference > 0)
{
m_arColWidths[ nLastColumn ] += nDifference;
Refresh();
}
In my case is nDifference allways less then 0, how to use this function properly!?
regards
bosfan
|
|
|
|

|
Hi Friends,
I have a table with UNICODE data. Now I am going to display that data in MFC Grid Control.
But the Data is not displayed in the Grid, Instead it displays some "?????" Question marks.
please help me how to fill/display UNICODE data in the MFC grid control
Thanks in Advance
Gouse Shaik
|
|
|
|

|
Working with a pretty simple grid; it is not editable -- the user can only select cells. I have a GVN_SELCHANGED / OnGridSelChanged() function that alerts me when the user chooses a new cell. Usually this works fine, but in this new program there's a wrinkle. If they choose certain cells I need to display a simple error message in a modal dialog. I open that modal dialog within OnGridSelChanged(). What was unexpected is that when the modal dialog is closed the grid goes a little nutsy; it acts like the user has made a bunch of new mouse clicks on other cells. Almost as if it were tracking the mouse while the modal dialog is up. I tried various things to squelch this weirdness -- invalidating the grid, turning off redraw when the modal window comes up, resetting the focus after the modal window is closed, etc. Nothing seems to help. Also tried adding the following code at the start of the function as per an old thread here about ignoring extra mouse clicks from the user:
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
if(pItem->iRow<0) return;
Nothing seems to improve or even change the behavior. Any wisdom about what I'm doing wrong?
Thanks, Allan
modified 22-Sep-11 3:56am.
|
|
|
|

|
I was able to get around the problem, and thought I should tell what I found. It seems that the grid does indeed have a problem in the OnTimer() function; it 'sees' mouse movements that occur when a modal dialog has the focus (how and why that happens I dunno). Anyway, I noticed that the (rather skimpy) comment on that function says that its purpose is to deal with drag-selection. Since I don't use that feature for selecting multiple cells I just ifdef'ed out the entire code. Elegant? No. But it put an end to the craziness that was going on in the grid when I popped up a modal dialog.
To test my theory I put a breakpoint in OnTimer() (outside the ifdef of course) and tried to stimulate a call to it in various ways. Couldn't make it happen. If anyone knows why I need OnTimer() to do something if not using drag-selections I'd appreciate a heads-up.
Is there a more elegant solution to this problem?
--Allan
|
|
|
|

|
Hi,
I need to display the UNICODE data in the MFC Grid. What are the properties I need to set.
Please provide me one sample code for this.
Waiting for your valuable reply.
Thanks & Regards
Gouse Sahik
|
|
|
|

|
I have used the method GridObject.Print() for printing.
It printed to printer but with very small font etc..
I need good printing of preferred page size.
How to do ? I am using grid control in Dialog based Application.
|
|
|
|

|
I also meet this problem,my printed font is large
|
|
|
|

|
Chris:
I needed to do some validation of data entry in the form's OnNotify, and discovered that the result of GVN_ENDLABELEDIT processing in OnNotify (the form returns FALSE if input is invalid) was not making it back up to the GridCtrl and the InPlaceEdit instances.
The reason this came up is because I wanted to use EM_SHOWBALLOONTIP to give hints to the user. Making that worked required conserving the InPlacedEdit when FALSE is reported.
I also had some fun with tabbing into a GridCellCombo-controlled cell and having the TAB's KeyUp causing the in-place editor to immediately close, thus sliding immediately into the next cell.
I've modified a number of the files to deal with these problems. How do I get them to you to evaluate?
Brian
|
|
|
|

|
If more rows or columns are needed than space allows, the scroll bars are not visible until an InsertColumn() operation is performed. Otherwise, this is an excellent control.
|
|
|
|

|
Modifying the style doesn't show an effect.
For example:
m_Grid.ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
I added a handler (in CGridCtrl) for WM_STYLECHANGED:
In GridCtrl.h:
afx_msg void OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct);
In GridCtrl.cpp:
ON_WM_STYLECHANGED()
and
void CGridCtrl::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
{
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
BTW:
In CGridCtrl::Initialise() I replaced:
CRect rect;
GetWindowRect(rect);
CWnd* pParent = GetParent();
if (pParent != NULL)
pParent->ScreenToClient(rect);
rect.InflateRect(1,1); MoveWindow(rect);
rect.DeflateRect(1,1); MoveWindow(rect);
with
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
|
|
|

|
I am using MFCGridCtrl in CDialogEx. I am using WM_SIZE message handler to resize the control as:-
void CNewPurchaseDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
m_PurchaseParticulars.ExpandColumnsToFit(FALSE);
}
first time when i show the Dialog box then GridCtrl resizes properly and CGridCtrl hWnd=0x000207ce. then i close dialog box.
But when i display the Dialog box second time it causes Debug Assertion failure.
also in second case the CGridCtrl hWnd=0x00000000
I am using resizing class MFC/C++ Helper Class for Window Resizing[^]
#########
SOLUTION# ---->>
#########
Ok, I figured it out what was I missing.
Unfortunately, the OnSize routine can be called very early; WM_SIZE is one of the first five messages sent when a window is created. This means that at the time the dialog is created, the OnSize handler is called, but none of the controls have been created yet!
Both of these problems can be solved by adding an extra variable to the dialog class. Add a protected variable, "BOOL initialized". In the dialog class constructor, set "initialized" to FALSE.
You must set this in the constructor, not in OnInitDialog, because by the time you get to the assignment in OnInitDialog it is far too late. To protect against the possibility of accessing an invalid variable, you just check the initialized variable. For example,
void CMyDialog::OnSize(UINT nType, UINT cx, UINT cy)
{
CDialog::OnSize(nType, cx, cy);
if(!initialized)
return;
}
and
void CNewPurchaseDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
if(!initialized)
return;
m_PurchaseParticulars.ExpandColumnsToFit(FALSE);
}
void CNewPurchaseDlg::OnOK()
{
initialized = FALSE;
CDialogEx::OnOK();
}
void CNewPurchaseDlg::OnCancel()
{
initialized = FALSE;
CDialogEx::OnCancel();
}
Reference : http://www.flounder.com/getdlgitem.htm[^]
Future Lies in Present.
Manmohan Bishnoi
modified on Sunday, August 7, 2011 9:43 AM
|
|
|
|

|
You don't need and extra variable to do this, just verify the gird has a valid wnd handle like:
::IsWindow(m_Grid.GetSafeHwnd())
|
|
|
|

|
Hello Everyone,
I am trying to sort my grid control column with text. I have one issue. When i am sorting everything in ascending order it puts "AA" before "aa", how to reverse this, does everyone see the same problem or has anyone solved. it.
I am also using
"m_gridctrlProperties.SetCompareFunction(CGridCtrl::pfnCellTextCompare);" but its not helping.
Help Please!! At least tell me if this is what you are seeing.
|
|
|
|

|
Replace CGridCtrl::pfnCellTextCompare by your own comparison function.
The way to proceed is described just above
/.../
The comparison function must be a global or static function with the form
Collapse
int CALLBACK pfnCellCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
/.../
You can retrieve the cell text in your comparison function.
Convert compared strings in upper or lower case in your comparison function, then use strcmp or even stricmp (to avoid upper/lower conversion), and return the strxxx function result.
That's it (it works like a charm...)
|
|
|
|

|
hi,all, I know there is a CMemDC naming conflict problem in the code, but the GridGtrl demo project seems working fine, and it didnt rename the CMemDC class, so whats the magic here?
cheers
|
|
|
|

|
Hi,
either you rename the CMemDC included in the GridCtrl ...
... or use that one from afxcontrolbarutil.h:
void CGridCtrl::OnPaint()
{
CPaintDC dc(this);
if (m_bDoubleBuffer) {
CMemDC memDC(dc, this);
CDC* pDC = &memDC.GetDC();
OnDraw(pDC);
}
else OnDraw(&dc);
}
|
|
|
|

|
We have also been running into this naming conflict. I agree to your suggestions. We have decided to get rid of this very old MemDC.h file and to use CMemDC from afxcontrolbarutil.h.
Thomas Haase
|
|
|
|

|
The gray areas at the end of both horizontal and vertical scrolling make this otherwise very nice control look unprofessional. Is there any way to get rid of these?
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
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,868,057 |
| Downloads | 113,323 |
| Bookmarked | 1,134 times |
|
|