|
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
|
|
|
|
|
The control won't compile under UNICODE. Does anyone have a UNICODE compliant version?
- Matt Newman / Windows XP Activist
-Sonork ID: 100.11179:BestSnowman
†
|
|
|
|
|
The control has always compiled under Unicode. What errors are you seeing?
cheers,
Chris Maunder
|
|
|
|
|
Hi,
Using your example, GridCtrlDemo, say i have 2 columns in the grid. The 2nd column
contains a verry looong string within one of it's cells. Say you then resize the dialog smaller(resize dialog towards your left). A horizontal scroll bar then appears at the bottom of the grid. But if you notice, when you scroll the bar, the 2nd column gets cut off (you cannot see the full contents of the string of the long data). Does anyone know how to modify the grid, such that when someone resizes the dialog, the user can still
scroll the whole data? or is this impossible?
Thank-you!!!!!!!
Eric
|
|
|
|
|
Doesn't anyone can tell me how to do it?Please!
|
|
|
|
|
I had built this program and I got the following error.
fatal error LNK1104: cannot open file "mfc42u.lib"
Please help.
I am just a beginner.
Cheolsoon
|
|
|
|
|
Hi all
I really need this bad, I got the grid, but i need to capture any changes in cell data. Its like this when a cell data is changed simultaneously i need to change another variable whoes value depends on the cell data. It would take lot of time if I try to compare teh values of each cell with respective previous values and then change teh variable value. So any suggestions how to do it?/
Thank you
Cheers
|
|
|
|
|
Please tell me how to merge the cells, you know, in the table-making work, we always need merge the cells to make them to be a large cell, just like the merge function in Exell.
Tell me please, thanks a lot.
|
|
|
|
|
Anyone know how to wrap text onto multiple lines within a cell?
defualt behaviour is to spill text out the right side.
Thanx,
Robert
Robert-laird@home.com
|
|
|
|
|
I have used this grid as in splitter view as one of the four views.
And succesfully draw the grid inthat view,but iam unable to resize the cols and rows size by dragging the mousefrom the edge of the cell.
please help me.
Also I am unable to trap Mouse generated messages e.g. OnLButtonDown.
What happens is that the control always go to CGridCtrl's trapped message.
Please help me
leens
|
|
|
|