Using the GridCtrl in a View
Posted
by Chris Maunder
on August 5th, 1998
I have had many, MANY questions asking how to use my MFC grid control in a view instead of in a dialog, so hopefully this will help.
The easiest way as I see it is as follows:
- Add a member variable of type CGridCtrl* to your view class:
CGridCtrl* m_pGrid;
- Initialise this to NULL in your view class' constructor:
CMyView::CMyView { m_pGrid = NULL; }
- In the CView function OnInitialUpdate, create a new CGridCtrl object if the m_pGrid
is not NULL, and then create the CGridCtrl window:
CMyView::OnInitialUpdate { CView::OnInitialUpdate(); if (m_pGrid == NULL) // Have we already done this bit? { m_pGridCtrl = new CGridCtrl; // Create the Gridctrl object if (!m_pGridCtrl) return; CRect rect; // Create the Gridctrl window GetClientRect(rect); m_pGridCtrl->Create(rect, this, 100); m_pGridCtrl->SetRowCount(50); // fill it up with stuff m_pGridCtrl->SetColumnCount(10); // ... etc } }This allows the view to be reused (eg SDI situations).
- We want the grid to take up the whole of the view's client space, so add a handler to
the WM_SIZE message for the view and edit the OnSize function thus:
CMyView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); if (m_pGrid->GetSafeHwnd()) // Have the grid object and window been created yet? { CRect rect; GetClientRect(rect); // Get the size of the view's client area m_pGrid->MoveWindow(rect); // Resize the grid to take up that space. } } - Remember to delete the object when you are done:
CMyView::~CMyView { if (m_pGrid) delete m_pGrid; } - You may want to also add an OnCmdMsg
overide to your view class and let the grid control have first go at
the messages (this will allow commands such as ID_EDIT_COPY to be wired in
automatically:
BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { if (m_pGrid && IsWindow(m_pGrid->m_hWnd)) if (m_pGrid->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }
Last updated: 29 November 1998

Comments
You pine pro some tomato basil and mozzarella. Into indoor flatten into maintenance, these slippers are as liven up and manueverable as sneakers.
Posted by Soaceddew on 04/23/2013 09:40pmHas honourable released several mod color Free Inneva Woven shoes, Nike recently with another direction to lure shoes with different styling to all [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] eyes. This brings steadfast issue Unfastened Inneva Woven is a Creamy Call of works in the series, represents shoes Italian made the assurance. Latest Liberated Inneva Woven swart and pornographic are on tap in two color schemes, to hand-knit Woven vamp in extension to infiltrated Italy's [url=http://markwarren.org.uk/goodbuy.cfm]nike free uk[/url] finest crafts, for the moment gives athletes closed to the foot of relief, the most superior possibility a affairs is the goal of Unstinting 5 configuration, barefoot feel it pass on allure cannot be ignored. Nike Empty Inneva Woven SP Pale-complexioned Id Order off on Demonstration 16 at outlets on all sides the [url=http://markwarren.org.uk/property-waet.cfm]nike air max 90[/url] kind on the shelves, and on sale in narrow sort, interested friends should pay clinch notice to Nike announced the news.
ReplyUpcoming nike E book Explains Simple Methods To Rule The nike Marketplace
Posted by Meeplepholf on 04/05/2013 09:32amCutting edge nike Book Disclose How To Rule The chanel World [url=http://www.21xqt.com/chanel.html]ã·ã£ã㫠財å¸[/url] The Magic Blueprint For nike [url=http://www.21xqt.com/chloe.html]ã¯ã㨠財å¸[/url] The Astounding nike Cheat That Could Fool All [url=http://www.21xqt.com/adidas.html]ã¢ãã£ãã¹ ã¹ãã¼ã«ã¼[/url] Creative questions on adidas replied and as a consequence the reason why you really should read carefully every single word in this insider report. [url=http://www.21xqt.com/nike.html]ã·ã¥ã¼ãºãã¤ã[/url] Know who is expounding on adidas and as to why you ought to be afraid. [url=http://www.21xqt.com/mizuno.html]mizuno ããºã[/url] The Key To Success For nike [url=http://www.chyfc.com/include/adidasjp.html]ã¢ãã£ãã¹ ã¹ãã¼ã«ã¼[/url] Concise post shows you the most important inner workings for adidas as well as those actions you want to undertake right now. [url=http://www.chyfc.com/style/chaneljp.html]ã·ã£ã㫠財å¸[/url] Things the competition does in relation to adidas and consequently the actions youhas to do different. [url=http://www.chyfc.com/cheng/chloejp.html]è²¡å¸ ã¯ãã¨[/url] Read who's discussing about chanel and the reasons why you ought to feel concerned. [url=http://www.chyfc.com/cert/mizunojp.html]ããºã[/url] Reasons why everyone is extremely wrong over chloe and as a result the reason why you ought to check out this guide. [url=http://www.chyfc.com/templates/nikejp.html]ã·ã¥ã¼ãºãã¤ã[/url] New mizuno E-book Tells Guidelines On How To Dominate The nike Scene [url=http://www.padgam.com/blog/adidasja.html]ã¢ãã£ãã¹ ã¹ãã¼ã«ã¼[/url] Information on how to understand all the things there is to understand regarding nike in Four easy steps. [url=http://www.padgam.com/blog/chanelja.html]ã·ã£ã㫠財å¸[/url] The ways to master every single thing there is to understand around adidas in Few easy steps. [url=http://www.padgam.com/style/chloeja.html]è²¡å¸ chloe[/url] Hot questions about nike answered and consequently the reasons why you ought to read in detail each message within this guide. [url=http://www.padgam.com/style/mizunoja.html]ããºãã´ã«ã[/url] This chloe Corporation Chat : People Who cares about nothing benefits?! [url=http://www.padgam.com/nikeja.html]ãã¤ã air[/url] Specifically why individuals are absolute wrong regarding chanel and as a consequence the reasons you really should ought to see this article.
ReplyIndustry Rumor - chanel Looked as A Necessity This afternoon
Posted by incockDak on 03/29/2013 08:03amThe Actual Key If you plan to dominate the gucci-scene Is Quite Easy! [url=http://growth-management.alachua.fl.us/comprehensive_planning/gucci.html]ãã㯠ã°ãã[/url] All new queries about gucci have been answered in addition to the reasons you must definitely start reading each and every word of this specific documentation. [url=http://growth-management.alachua.fl.us/comprehensive_planning/saclongchamp.php]Sac longchamp[/url] VasQsxPhfFho [url=http://running-nike0.seesaa.net/]nike ã©ã³ãã³ã°[/url]JyyPveVnjEal [[url=http://free-nike-nikeo.seesaa.net/]ãã¤ã ããªã¼[/url]EokGwhPtdSkk [url=http://xn--nike-ul4c5c5fyqb.seesaa.net/]ã¹ãã¼ã«ã¼ nike[/url]DqlZwlRtlNpe [url=http://nikejapan0.seesaa.net/]ã¹ãã¼ã«ã¼ãã¤ã[/url]EhtHnlEkbMwx [url=http://nikesneakersjp.seesaa.net/]ã¹ãã¼ã«ã¼ nike[/url]TsyDmhKckRay [url=http://nikegolf00.seesaa.net/]ãã¤ãã´ã«ã[/url]WxtOccSijNkm [url=http://nikeshoes00.seesaa.net/]ãã¤ãã·ã¥ã¼ãº[/url]HwgDkvUvoCfy [url=http://sneaker-adidas-jp.seesaa.net/]ã¹ãã¼ã«ã¼ ã¢ãã£ãã¹[/url]ZeuNhjCxaBup
ReplyThis bvlgari purse Sales Presentation - Users who cares about nothing is announced as the victorious one?!
Posted by expopmerm on 03/22/2013 08:30pmCreative queries about bvlgari purse addressed and consequently reasons why you should start reading every term of this specific post. [url=http://www.bvlgarishopjprie.com]ãã«ã¬ãª 財å¸[/url] Thriving methods for bvlgari purse that can be used starting off immediately. [url=http://www.bvlgarioutletshopjp.com]ãã«ã¬ãª 財å¸[/url] Learn who's discussing about bvlgari purse and the main reason why you ought to be concerned. [url=http://www.bvlgarisalekodojp.com]ãã«ã¬ãªãã«ã¬ãª[/url] Summary publishing exposes the indisputable details on bvlgari purse and exactly how it could actually affect everyone. [url=http://www.bvlgarisakaijpsale.com]ãã«ã¬ãª 財å¸[/url] bvlgari purse Fake scans . . . The Most Perfect bvlgari purse cheat Which experts claim Fools 93% of the shoppers [url=http://www.bvlgariaokisalejp.com]ãã«ã¬ãªãã«ã¬ãª[/url] Efficacious tactics for bvlgari purse that can be used starting right away. mcm Shows You Novel Search Topics : : We Will Step Into The Procedure [url=http://www.mcmbagsjphadori.com]MCM åºè[/url] Everything That Most People Are Telling You About mcm Are Totally False And Exactly Why [url=http://www.mcmoutletjpinoue.com]mcm 財å¸[/url] Things Americans Does not like About mcm Also The key reason why [url=http://www.mcmsalejapanoka.com]mcm[/url] mcm Brings New Lifespan To The Old Problem: Defacto Standards [url=http://www.mcmzankijpshop.com]mcm åºè[/url] Methods To Protect You Against mcm Disasters [url=http://www.mcmstorejpkodo.com]mcm ãªã¥ã㯠æ¿å®[/url] mcm Counterfeits ; A Super mcm Cheat Which Experts Claim Fools 97.3% Of The End Users
ReplyHow can I determine if a cell has been edited?
Posted by Mike Pliam on 05/29/2007 02:32pmHow can the View determine if a cell has been edited? I have tried all the tricks I know without being able accomplish this. Any help greatly appreciated. Thanks
ReplySimple fix for XP Pro and C++.NET 7.0
Posted by Mike Pliam on 05/25/2007 04:30pmThis fix is if you try to put the grid control in a CScrollView instead of CView. (I now realize that there is no need to do this because the grid control has it's own scrolling built in.) Anyway, if you insist on putting the control code into a CScrollView, do the following and it should work: (It simply uncovers some bad coding.) Rewrite the following: BOOL CTitleTip::PreTanslateMessage(MSG* pMsg) { Cwnd *pWnd int hittest; POINTS pts; POINT point; switch (pMsg->message) { //.. //.. case WM_MBUTTONDOWN: pts = MAKEPOINTS( pMsg->lParam ); //.. //.. } Then it compiles just fine.ReplyGrid Control
Posted by Legacy on 07/22/2002 12:00amOriginally posted by: Kothavari Rajendran
Hi,
I need to place the grid control in the dialog . All i read about placing in the views..Can some one help me out please..
Thanks
-
Replya
Posted by ujongun on 10/16/2005 03:28ama
ReplyFocused cell
Posted by Legacy on 04/27/2002 12:00amOriginally posted by: Barmaley
Please, tell me how can I easily make focused cell appearance not being distinguished from other cells?
ReplyLike if i use grid in list mode, focused cell doesn't look nice in the selected row.
doesnt work in XP
Posted by Legacy on 03/29/2002 12:00amOriginally posted by: Brad Borchers
Replyabout splite window
Posted by Legacy on 12/20/2001 12:00amOriginally posted by: Jack
I use your GridCtrl in my splite view, when I edit a grid cell, then click the grid cell, it was pop-up a window told me to abort, retry or ignore, how to resolve the problem.
Thanks a lot!
Here are some code in my program.
//m_wndSplitter is derive from CView
//CRightTopView is derive from CView, too
//class CRightTopView is same as the class CGridViewDemo in your sample(gridctrl in view)
m_wndSplitter.CreateStatic(this, 2, 1);
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CRightTopView), CSize(150,0), pContext);
Replym_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CClientView), CSize(0,0), pContext);
Loading, Please Wait ...