|
|
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
|
|
|
|
|
 |
|
|
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,855,081 |
| Downloads | 112,137 |
| Bookmarked | 1,131 times |
|
|