|
For some reason, every example of yours does not have and edge on the grid conrol. But when I use it I can't seem to get ride of the edge no matter what flags I use in the create call or the modifiyWindow call.
Any suggestions?
Regards,
Rick
|
|
|
|
|
The grid itself sets the window style to have a client edge. You'll have to manually change this in the gridctrl.cpp file.
cheers,
Chris Maunder
|
|
|
|
|
Try this in your CView::OnInitialUpdate()
if (m_pGrid == NULL)
{
m_pGrid = new CGridCtrl;
if (!m_pGrid ) return;
CRect rect;
GetClientRect(rect);
m_pGrid->Create(rect, this, 100,WS_CHILD | WS_VISIBLE);
m_pGrid->ModifyStyleEx(WS_EX_CLIENTEDGE, 0,0);
} John
|
|
|
|
|
The grid works perfectly.
I just don't know how to implement the dbl click event on a cell.
I'd like to know when the user dbl clicked on a cell and then I would handle this event as I want.
Life is short. Drink Faster
|
|
|
|
|
Hi
I am a beginner with grid control (and with MFC).
I add the files and some lines in my project to display a grid in the MainFrame. When I use ReDrawRow(x) it returns TRUE and I can see the Main Frame but the grid has been diplayed in the Main Frame.
Someone can help me?
thank you
Martin
|
|
|
|
|
Hi all!
I ask myself can CGridCtrl be used in building spreadsheet applications like Excel.
I try to make SDI application with CGridCtrl and put in View OnInitialUpdate func.
Also in CGridCtrl::OnLButtonDown tried to put code to receive text from cell but I don't know how to get it.
Any help is appreciated.
Thanks
|
|
|
|
|
I have a Windows 98 machine. When I attempt to run the demo executables or compile the project I run into all sorts of problems.
GridCtrlDemo.exe
Need MFC70.dll
Windows cannot run this program because it is in an invalid file format.
When I attempt to compile GridCtrlDemoCE.dsw
This project does not contain any configurations whose platforms are supported by this installation of developer studio. You will need to create a new supported configuration before you will be able to build, run or debug your project.
What does all that mean? What's the difference between GridCtrlDemo and GridCtrlDemoCE?
When I attempt to compile GridCtrlDemo.dsw. Compiles fine but then when I run the executable it says.
This application or dll cannot be loaded on Win95 or on Win 3.1
It takes advantage of Unicode features only available on NT.
Then I get a MFC42u.dll error
Generally I've found when you can't get demos to run it's a good idea to keep looking.
Any help would be appreciated.
Thanks Jay
|
|
|
|
|
Hi,
Thanks for the great grid control.
I'm using the control in the Doc/View framework and was wondering how I would be able to set(?) the row count so that it changes according to the size of the view.
Thanks alot in advance!
|
|
|
|
|
Only a idea, don't know if it works:
if you have the size of the client area of your view, you can calculate the rows needing using the default cell height size... sample:
CRect rc;<br />
GetClientRect(&rc);<br />
myGrid.SetRowCount(rc.Height() / myGrid.GetDefCellHeight());
Let me know...
|
|
|
|
|
Thank you for the input.
I'm not sure why, but the suggested solution doesn't work. Regardless of the size of the view (ClientRect), the number of rows stay static. I understand that I need to get the size of the view and somehow apply that to the size of the grid... But I haven't quite figured it out yet. Any other suggestions would be much appreciated.
Thanks!
|
|
|
|
|
Hi,
I made some different tries, and my idea worked in my case . Probably the problem is "where" you put the row calculation code.
Here some samples:
in the WM_SIZE message (you must try to resize the view)
void CMyView::OnSize(UINT nType, int cx, int cy) <br />
{<br />
CView::OnSize(nType, cx, cy);<br />
<br />
if (m_pGridCtrl && IsWindow(m_pGridCtrl->m_hWnd))<br />
{<br />
m_pGridCtrl->MoveWindow(CRect(0,0,cx,cy));<br />
<br />
if (m_pGridCtrl->GetDefCellHeight() > 0)<br />
m_pGridCtrl->SetRowCount(cy / m_pGridCtrl->GetDefCellHeight());<br />
}<br />
}
in the CMyView::OnIntialUpdate()
CMyView::OnInitialUpdate<br />
{<br />
CView::OnInitialUpdate();<br />
<br />
if (m_pGrid == NULL)
{<br />
m_pGridCtrl = new CGridCtrl;
if (!m_pGridCtrl) return;<br />
<br />
CRect rect;
GetClientRect(rect);<br />
m_pGridCtrl->Create(rect, this, 100);<br />
<br />
if (m_pGridCtrl->GetDefCellHeight() > 0)<br />
m_pGridCtrl->SetRowCount(rect.Height() / m_pGridCtrl->GetDefCellHeight());<br />
m_pGridCtrl->SetColumnCount(10);<br />
<br />
}<br />
}
If you want, where you want, you can try a "variation", like:
CRect rc;<br />
myGrid.GetWindowRect(&rc);<br />
myGrid.SetRowCount(rc.Height() / myGrid.GetDefCellHeight());
The last piece of sample can be used anyware, especially if you don't use the CGridCtrl in a CView derived class. For sample, in a Dialog, put the above code in the WM_INITDIALOG message.
Repeat all the same context for the colums.
Anyway, I never use an initialization like this. In my case I prefer to put the background color of the CGridCtrl control, the same color used by the background of the cell. This is the color setup I put in my beginning code:
m_pGridCtrl->SetBkColor(::GetSysColor(COLOR_WINDOW));<br />
m_pGridCtrl->SetFixedBkColor(::GetSysColor(COLOR_3DFACE));<br />
m_pGridCtrl->SetGridLineColor(::GetSysColor(COLOR_3DFACE));
For me, the cell-size of the grid depends only on the application needing.
With my samples, you risk to loose important data-cells.
Now I was trying to implementing a "dynamic" Grid row/cell resize, depending on the "user" actions.
For sample, if the user is "editing" in the last aviable row, then the program must add a new row... same for the colums. But this is for a specific needing where the beginning grid size is very small (2r x 3c).
Let me know...
|
|
|
|
|
Ahhh, yes, you're right. Your idea does work. I just needed to additionally modify the OnSize. Thanks again for your help! I really appreciate it.
|
|
|
|
|
Great article - I've found it very helpful. My question is - what is the best way to let the document know that the data has been modified in the view (which contains the grid control)? I want the framework to prompt the user to save the document if it has been modified. I already have the serialization working (thanks to Holger Persch).
Tom Pruett
|
|
|
|
|
Get a pointer to the document and then call CDocument::SetModified
cheers,
Chris Maunder
|
|
|
|
|
I've tried to have the grid gain the focus when a new child window is opened or when the user switch back to the grid demo application.
I've added a handler for OnActivateView:
<br />
void CGridViewDemoView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) <br />
{<br />
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);<br />
if (bActivate && this == pActivateView)<br />
m_pGridCtrl->SetFocus();<br />
}<br />
But that doesn't seem to do anything...
Any idea someone ?
Pierre Meindre
|
|
|
|
|
Did you try the OnSetFocus?
void CGridViewDemoView::OnSetFocus(CWnd* pOldWnd) <br />
{<br />
CView::OnSetFocus(pOldWnd);<br />
if (m_pGridCtrl && IsWindow(m_pGridCtrl->m_hWnd)) m_pGridCtrl->SetFocus();<br />
}
|
|
|
|
|
Thanks for your answer.
Is it working for you ?
I've just added a WM_SETFOCUS handler as you suggested,
it get called indeed (down to the m_pGridCtrl->SetFocus()
call) but... nothing more is happening!
What I want to acheive is to have the focus set on the grid
so using the keyboard is active: moving the current cell with
the cursor keys, pressing F2 or Enter to edit a value...
|
|
|
|
|
Ok, I made a try... it worked this way:
void CMyView::OnSetFocus(CWnd* pOldWnd) <br />
{<br />
CView::OnSetFocus(pOldWnd);<br />
<br />
if (m_pGridCtrl && IsWindow(m_pGridCtrl->m_hWnd))<br />
{<br />
m_pGridCtrl->SetFocus();<br />
<br />
int x = m_pGridCtrl->GetFixedColumnCount();<br />
int y = m_pGridCtrl->GetFixedRowCount();<br />
m_pGridCtrl->SetFocusCell (y,x);<br />
m_pGridCtrl->EnsureVisible(y,x);<br />
}<br />
}
|
|
|
|
|
What the best way to save grid control in CDocument class with Serialize function?
|
|
|
|
|
Row selection doesn't work for me like normal window row selection.
I left click on a row and it selects. I left click on it a second time and it unselects. I would like it to stay selected, like in Windows Explorer etc. (In Windows Explorer click on the icon in font of the file name.) Row selection is fine if I move the mouse a little before the left button up.
I'm working with MFC Grid Control v2.23. The problem seems to be that on line 6158 in CGridCtrl::OnLButtonUp does ResetSelectedRange.
My grid is read-only and enabled for drag-and-drop.
If anyone has a fix for this, I'd appreciate it. Otherwise I'll look at it some more. If I figure out a fix, I'll post it.
|
|
|
|
|
See my fix under the project "MFC Grid control 2.23".
|
|
|
|
|
|
Hi,
When i tried to add a member variable of type CGridCtrl* to the view class as u said like...
in ".h" file of CView derived class
CGridCtrl* m_pGrid;
the compiler gives some error.
So, i did downloaded your application and tried to run, again it was the same error.
The compiler(MSVisual Studio 6.0) errors are...
error C2143: syntax error : missing ';' before '*'
error C2501: 'CGridCtrl' : missing storage-class or type specifiers
Errors:.....
Can i have some explanation please?
Thanking you
Regards
Mohan
|
|
|
|
|
Have you include 'GridCtrl.h' in the "MyView.h" file of your CMyView
|
|
|
|
|
Have you included 'GridCtrl.h' in the "MyView.h" file of your CMyView
|
|
|
|