|
|
Comments and Discussions
|
|
 |

|
Is there any way to merge two or more cells? Especially for header cells.
I found following link for merging cells:
Adding "Merge cells" support to the MFC GridControl
But there is some issue in merge cells.
I have merged following cells:
m_iCols = 20;
m_Grid.MergeCells(0,2,0,m_iCols-1); // 0 row
m_Grid.MergeCells(2,0,2,1); // 2 row
m_Grid.MergeCells(0,0,0,1); // 0th row
m_Grid.MergeCells(1,0,1,1); //1 row
I am using MFC grid control 2.27.
I have 20 rows and 20 columns. 4 rows are fixed row and 1 columns is fixed.
The grid visible portion has 10 rows and 6 columns. After 5th column we can view columns by scrolling. There is no problem until the grid is scrolled. But when we edit column 6 onwards and click on anywhere in grid, merged cells' text is hidden. Border of cell is not visible for merged cell and in header cell (0, 0) copies the text of cell (0, 2) cell.
|
|
|
|

|
Using Visual Studio 2010 C++. I'm successfully using the grid control (I have the grid source files directly in my project) but now I want to subclass it. How do I sub class the GridCtrl? When I do "Add Class..." and choose MFC Class which brings up the Class wizard, CGridCtrl is not present in the "Base Class" combo box.
|
|
|
|

|
What I ended up doing which seems to work is to still use the class wizard to create the subclass but just choose CWnd as the base class. Then I went through the generated code and replaced relevant references to CWnd with CGridCtrl.
|
|
|
|

|
Hi Gurus
I try to show multiline text (strings containing '\n') in the Grid Control.
But whatever I try it fails.
There is an older thread in here about this, telling to use DT_WORDBREAK as item format flag and/or to call AutoSizeRows()
I modified the demo to do this when I press in the "Cell 1,1 Normal" radio button:
>>>
void CGridCtrlDemoDlg::OnCellNormal()
{
// m_Grid.AutoSizeRows();
UINT fmt = m_Grid.GetItemFormat(1,1);
fmt |= DT_WORDBREAK;
m_Grid.SetItemFormat(1,1,fmt);
m_Grid.SetCellType(1,1, RUNTIME_CLASS(CGridCell));
m_Grid.SetItemText(1,1, _T("0123456789 \n 123456789"));
m_Grid.SetItemState(1,1, m_Grid.GetItemState(1,1) & ~GVIS_READONLY);
m_Grid.Invalidate();
}
<<<
But this had absolutly no effect. I still see "..." (or a wider cell when using the AutoSize methods) instead of multiple lines
Can anyone help me? A code snippet would be great
Regards,
Bernd
modified on Friday, May 6, 2011 7:51 PM
|
|
|
|

|
This is a little late, but try removing the DT_SINGLELINE, ie...
fmt |= DT_WORDBREAK;
fmt &= (~DT_SINGLELINE);
|
|
|
|

|
Can we make non editable any row or any column or any cell. SetFixedRowCount () and SetFixedColumnCount () functions make non editable some of starting rows or columns.
But we want to make non editable row or column or cell anywhere in grid.
|
|
|
|

|
In Code:
BOOL CGridCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
...
if(GetCell(GetFocusCell().row, GetFocusCell().col)->OnNotify(wParam, lParam, pResult))
{
...
}
if no focused cell GetCell will return NULL.
When GetCell==NULL - OnNotify crash;
FIX:
BOOL CGridCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
...
CGridCellBase* pCell=GetCell(GetFocusCell().row, GetFocusCell().col);
if(pCell && pCell->OnNotify(wParam, lParam, pResult))
{
...
}
Sorry my bad english;
|
|
|
|

|
Hello
I want to use check or uncheck only on the check box area.
How can I do that???
Thank you for reading.
|
|
|
|

|
In ONLButtonUp function replace
SendMessageToParent(m_LeftClickDownCell.row, m_LeftClickDownCell.col, NM_CLICK);
with
if (pCell->IsKindOf(RUNTIME_CLASS(CGridCellCheck)))
{
CGridCellCheck* pCheck = (CGridCellCheck*)pCell;
if (pCheck->GetCheckPlacement().PtInRect(point)) SendMessageToParent(m_LeftClickDownCell.row, m_LeftClickDownCell.col, NM_CLICK);
}
else
SendMessageToParent(m_LeftClickDownCell.row, m_LeftClickDownCell.col, NM_CLICK);
but it send message just click on checkbox.
modified on Thursday, July 21, 2011 9:06 PM
|
|
|
|

|
My grid control has a fixed row and fixed column. Clicking on a column heading selects the entire column and then selecting copy copies the entire column to the clipboard as expected. Likewise, clicking on a row heading selects the entire row and the selecting copy copies the entire row to the clipboard. However, selecting the origin position (i.e., row 0 column 0, or the top left corner) highlights all cells but then copying does not copy anything. Select All from the keyboard (control-a) works.
How can I get get this to work?
|
|
|
|

|
If you have a grid with drag and drop enabled but without using virtual mode, CGridCtrl::Reorder will crash with runtime failure since m_arRowOrder is empty.
I've patched this function simply by
void CGridCtrl::Reorder (int From, int To)
{
if (!GetVirtualMode ())
return;
ASSERT(From>= GetFixedRowCount () && To >= GetFixedRowCount () - 1 && From < m_nRows && To < m_nRows);
...
|
|
|
|

|
Hi,
change
BOOL CGridCtrl::OnDrop(....)
{
...
else
{
if(m_bDragRowMode && m_bVirtualMode)
{
Reorder(m_CurRow,m_LastDragOverCell.row);
Invalidate();
return TRUE;
}
else
return PasteTextToGrid(m_LastDragOverCell, pDataObject, FALSE);
}
}
|
|
|
|

|
Is there a command which can select the special item by id for example?
for example I want to select second item on the row without clicking by mouse by me
modified on Saturday, March 5, 2011 7:50 AM
|
|
|
|

|
void MyDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
int x=m_Grid.GetRowCount()-2, y=0;
m_Grid.EnsureVisible(x,y);
m_Grid.SetFocusCell(x,y);
m_Grid.SetFocus();
CDialog::OnShowWindow(bShow, nStatus);
}
|
|
|
|

|
Hi,
MFC Grid Control rocks, just love it
however, I have one thing I can't figure out how to work out. I wan't to handle all the selected rows, like 1,3,4 10,11 rows selected.
How can I determine this?
Of course I could dig into the source, but I do think the API is prepared for this.
Thanks,
Nicholas
|
|
|
|

|
CWnd* pFocusWnd = GetFocus();
Here, pFocusWnd can be NULL if there is no input focus, which eventually blow up at line 5512 in GridCtrl.cpp
pFocusWnd->SetFocus();
Regards,
Ejaz.
|
|
|
|

|
Hello!
Can I create in this Grid cells with ellipsis button?
Yours Sincerely,
Alexander.
|
|
|
|

|
One computer in our office is getting this weird window. Here is a picture. Any thoughts on why that would happen?
Thanks,
John
|
|
|
|

|
This is the same appearance I have encountered when using the control in a DLL on a WinXP Pro machine. Is that the setting here ? If not, please spell out the OS and application environment.
|
|
|
|

|
In both the 2.26 and 2.27 source distributions, GridCtrl.cpp line 7 has a single slash '/'. Shouldn't this be a double-slash '//'?
|
|
|
|
|
|

|
Thanks for this fix.
Just to go sure: Is it correct, that you have changed 1300 to 1500?
Thomas
Thomas Haase
|
|
|
|

|
Hi Thomas,
I am glad it helped, it was a pain to trackdown so I tried to make my description "Google-friendly" so it could be found!
Quite sure it is still...
#if ((defined(_MSC_VER) && (_MSC_VER < 1500)) || (defined(WINVER) && (WINVER < 0x0600)))
Linkys:
Thread containing list of compiler codes
How version numbers map to full compiler names
MSVC++ 9.0 _MSC_VER = 1500 VS2008
MSVC++ 8.0 _MSC_VER = 1400 VS2005
MSVC++ 7.1 _MSC_VER = 1310 .NET 2003
MSVC++ 7.0 _MSC_VER = 1300 .NET 2002
MSVC++ 6.0 _MSC_VER = 1200 VC6
MSVC++ 5.0 _MSC_VER = 1100 VC5
I believe that we need to include VS2005 and the ".net" versions in the "list" of non-iPaddedBorderWidth structs, hence the change from 1300 to 1500.
We also need WINVER checks (See structs below) as iPaddedBorderWidth would be undefined if WINVER<0x0600
(Although the better solution might be to warn the user to increase his/her WINVER to at least 0x0600 "Windows Vista" when compiling! )
From http://msdn.microsoft.com/en-us/library/ms724506%28v=vs.85%29.aspx
typedef struct tagNONCLIENTMETRICS {
UINT cbSize;
int iBorderWidth;
int iScrollWidth;
int iScrollHeight;
int iCaptionWidth;
int iCaptionHeight;
LOGFONT lfCaptionFont;
int iSmCaptionWidth;
int iSmCaptionHeight;
LOGFONT lfSmCaptionFont;
int iMenuWidth;
int iMenuHeight;
LOGFONT lfMenuFont;
LOGFONT lfStatusFont;
LOGFONT lfMessageFont;
#if (WINVER >= 0x0600)
int iPaddedBorderWidth;
#endif
} NONCLIENTMETRICS, *LPNONCLIENTMETRICS;
Compare with my VS2005 SP1 install...
typedef struct tagNONCLIENTMETRICS {
UINT cbSize;
int iBorderWidth;
int iScrollWidth;
int iScrollHeight;
int iCaptionWidth;
int iCaptionHeight;
LOGFONT lfCaptionFont;
int iSmCaptionWidth;
int iSmCaptionHeight;
LOGFONT lfSmCaptionFont;
int iMenuWidth;
int iMenuHeight;
LOGFONT lfMenuFont;
LOGFONT lfStatusFont;
LOGFONT lfMessageFont;
} NONCLIENTMETRICS, *LPNONCLIENTMETRICS;
modified on Saturday, May 21, 2011 2:11 PM
|
|
|
|

|
Yes, your WINVER part is an important issue, that is missing in the original 2.27 code.
So, you should not comment it out
Thomas Haase
|
|
|
|

|
When we used original CGridCell code in VC++ 6.0 we dont have any issues. But when we used the same in VS 2005 we got the iPaddedBorderWidth error
\GridCtrl_src\GridCell.cpp(244) : error C2039: 'iPaddedBorderWidth' : is not a member of 'tagNONCLIENTMETRICSW'
We have removed the error but when we used the grid an unwanted row appears after first row. I do have an suspicion that this appears due to iPaddedBorderWidth. Does your fix correct the same? or what is the importance of iPaddedBorderWidth?
|
|
|
|

|
i have found 2 bugs list below:
1. it will be runtime error,when execute InsertColumn("test"),
but it is ok in last version.
i call SetColumnCount() and SetRowCount() and setItemText to avoid the bug;
2. scroll bar can work only if i invoke SetRowCount(largeNum),SetColumnCount(largeNum) in OnInitDialog function.
|
|
|
|

|
To use MFC in Static Library:
1. Need to rename CMemDC class - afxglobals.h and afxglobals.cpp have same name class.
2. Need to add oleacc.dll in Linker - Input - Delay Loaded Dlls
Mark Doubson
|
|
|
|
|

|
I use CGridCtrl for viewing records in OLEDB Consumer CRecord object. And I would like to use Insert, Delete and Return keys to edit record in dialog class. It's ok with Insert and Delete buttons, but VK_RETURN is not working.
Can anybody help me to solve this problem.
Thanks.
|
|
|
|

|
Where do you handle the VK_RETURN? I handle this in the PreTranslateMessage routine and there is no problem to get the VK_RETURN message.
HTH Frank
|
|
|
|

|
Yes, In PreTranslateMessage it works fine, but is it correctly?
|
|
|
|

|
There is no KeyDown notification i think. Maybe there is another solution that works over the OnNotify handler but as i have seen that it will work in PTR i have not searched for this.
Greetings,
Frank
|
|
|
|

|
Hi. I'm using SetSelectedRange() and GetSelectedRange() to select and determine which cells are selected in my grid. The only problem I have is that when I click on a cell with the mouse (which selects it), when I call GetSelectedRange(), it still only returns the cells that were selected with the SetSelectedRange() call - even though they no longer appear highlighted.
Can somebody help me please? I thought I would try and make my own class based on CGridCellBase that will automatically set the state of the cell to GVIS_SELECTED, but I can't compile this line:
pTrk->SetDefaultCellType( RUNTIME_CLASS(CMyCell) );
error C2039: 'classCMyCell' : is not a member of 'CMyCell'
Help please!
|
|
|
|

|
OK, I figured out the problem with RUNTIME_CLASS() but I get an exception:
UINT CGridCtrl::GetItemState(int nRow, int nCol) const
{
CGridCellBase* pCell = GetCell(nRow, nCol);
>>> ASSERT(pCell);
pCell is NULL.. My simple attempt at creating my own cell class below didn't work.. Back to the drawing board.
All I want to do is make mouse clicking cancel the programatically selected cells and select the row of cells where the mouse click took place. Isn't there a way to do this without me changing the source for CGridCtrl?
class CMyCell : public CGridCellBase
{
CMyCell();
virtual void OnClick( CPoint PointCellRelative );
DECLARE_DYNAMIC(CMyCell);
};
IMPLEMENT_DYNAMIC(CMyCell,CGridCellBase);
CMyCell::CMyCell() : CGridCellBase()
{
}
void CMyCell::OnClick( CPoint PointCellRelative )
{
SetState( GVIS_SELECTED );
}
|
|
|
|

|
I've derived a new cell class and it has a function I want to work when the user double clicks on the cell. This works great as long as the cell isn't being edited. But often the cell gets into edit mode using the InPlaceEdit class. This class doesn't pass the mouse double click message on to my class. Has anybody else needed this type of functionality and made it work without modifying the base classes?
Thanks,
Dave
|
|
|
|

|
I have experimented for several hours trying to install the grid in an SDI CRichEditView app. To my surprise, it works pretty well except for the fact that the vertical scrollbars of the CRichEditView appear in addition to those of the grid control. What's worse, the outer (CRichEditView) vertical scroll bar is out of synch with the inner (CGridCtrl) vertical scroll bar and the mouse wheel controls the outer scroll bar making a mess of the grid. The horizontal scroll bar seems to work OK.
I would like to hide the outer vertical scroll bar (CRichEditView) and keep the inner (grid control) scroll bar and the horizontal scroll bar, both of which work OK. I have not yet figured out how to do this. Are there any other known problems using CRichEditView instead of CView as provided in the MIDI example?
Your thoughts greatly appreciated.
|
|
|
|

|
I saw that ctrl+C/ctrl+V doesn't work when first column, first column after the selection column, is read only. In PasteTextToGrid method the function IsCellEditable(cell) returns false because the item state is read only. If I ignore this check everything is working fine, I can to copy/paste, but I don't know if this is a good approach. If will generate some strange bugs?
Any idea how we can resolve it.
Thanks,
Andu
Tine minte.
|
|
|
|

|
I am having the same issue, if the header (or) any fixed cell is of type cGridcellCheck, i cannot check the check box, coz its read only and onClickevent checks for it. I ignored the check and its working, but its not safe.
I haven't seen any functions to make it both fixed and editable cell. Have you ever resolved this issue? If you have any better approach please let me know
Thanks for your time.
|
|
|
|

|
Hello,
- I use GridCtrl version 2.20 in dialog base. I want bkground is set to other color when I LbuttonDblClk (no Editable Cell).
How to do it ?
Pls help me !
|
|
|
|

|
In Header:
...
afx_msg void OnGridDblClick(NMHDR *pNotifyStruct, LRESULT* pResult);
...
In Code:
...
ON_NOTIFY(NM_DBLCLK, IDC_GRID, OnGridDblClick)
...
void CDlg::OnGridDblClick(NMHDR *pNotifyStruct, LRESULT* /*pResult*/)
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
m_Grid.GetCell(pItem->iRow, pItem->iColumn)->SetBackClr(RGB(255,0,0));
m_Grid.Invalidate();
}
|
|
|
|

|
The return type of the assignment operator= must be non-const (and non-void), the returned object should be *this. This applies to GridCellBase.h/cpp GridCell.h/cpp and CellRange.h Andreas.
|
|
|
|

|
Hi Chris,
- First of all, you may want to consider including $TH's modification (can be found on this forum) so that the titletip uses the standard CToolTip class. It is automatically drawn themed (rounded frame, background colour transition, etc.) instead of the current ugly look. I use it for a year, without any problems.
- Furthermore, a new behaviour could be implemented for the titletip when it is displayed only if the cell text is truncated.
- In order to speed up column sorting drastically (and to get for customers what they expect for non-text columns, such as numbers, dates, etc.) I have a compare function that sorts by the cell item data. I set this compare function for the required columns.
- Just a small code style issue: why not make all the Get... functions const?
- I've implemented GVNI_DISABLED and GVIS_DISABLED style flags in order to prevent cell editing. (Not a big deal.)
Greets,
Yogurt
|
|
|
|

|
Dear friends.
I tried to download the 2.27 version of grid and I have received the 2.26 grid. Please provide us with correct 2.27 greed. I need t very much.
anatoly
|
|
|
|

|
The links point to the latest. However, I failed to update the internal docs so they still appear to be 2.26. They are, infact, 2.27
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|

|
The demo only seems to build a WIN32 version. Running this on a 64 bit machine seems okay.
1. But it doesn't seem to recognize CTRL-C and CTRL-V very often. I can hit them repeatedly and it doesn't seem to copy into the paste button reliably. It is obvious with CTRL-V that it doesn't work every time since it often doesn't show up in the grid. Using the pulldown commands works fine so why doesn't the keyboard commands?
2. I see in 2003 a post indicating code changes necessary for compiling in 64 bit environments. But those fixes were never implemented. I found that using it in a 64 bit application results in a number of crashes. Is this a known problem?
3. I fixed a number of issues I had and it seems to run but still has issues. One is that closing the dialog and then reopening it causes a crash. It seems that it never works opening a dialog with a grid a second time. Is this a known problem?
Thanks,
Dave
|
|
|
|

|
I have found that when I paste a block of cells in from MS Excel, it often comes out poorly. Any cell in Excel that has a return in the text is treated as a new cell delimiter.
Is there a mechanism to help the control know how to accept certain types of input? Being able to paste in from different apps would be a valuable benefit.
Thanks in advance for any help on this.
Jeff
|
|
|
|

|
After download the relative file, I try to run the GridCtrlDemo.exe in "gridctrl_demo227", but when I double click the icon there is no action, why?
My system is Windows XP.
|
|
|
|

|
Hello,every gentleman, who can tell me what style file I must use(txt,excel,dat...) if I want to save the grid content to it or load its content to grid.
Thanks!
|
|
|
|
|
 |
|
|
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,857,828 |
| Downloads | 112,410 |
| Bookmarked | 1,131 times |
|
|