Click here to Skip to main content
11,803,861 members (78,831 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VC8.0 C++ MFC
Dear All,

I am doing a visual C++ mfc dialog based application. In that I need to bring some data in a grid control.

I am able to add a grid control in my dialog. Following is the code to create a grid.

CMFCListCtrl m_listGrid2;
CRect rectDummy;
m_listGrid2.Create(dwStyle, rectDummy, this, IDC_LIST1);
m_listGrid2.InsertColumn(0, _T("Variable"), LVCFMT_LEFT, 100);
m_listGrid2.InsertItem(0, _T("b_A1GFHGKE"));

Here instead of putting a normal item, i need to have a checkbox column.BUt i am struggling how to add a checkbox in a grid.

Can anyone pls guide me in this??

Posted 24-Mar-11 21:30pm
Edited 24-Mar-11 21:38pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In CListCtrl you could use this extended style: LVS_EX_CHECKBOXES

Take a look at those posts here in CP:

Using Check Box in List Control[^]

Using the List Control[^]

CGridListCtrlEx - Grid Control Based on CListCtrl[^]

Hope this helps...
Siva_Si at 26-Mar-11 0:20am
Thank you so much Joan. I got it.
Siva_Si at 26-Mar-11 3:26am
Hi Joan,

Thanks a lot for your excellent answer. But I need one more assistance from you.

If i use this GetExtendedStyle, I am getting Checkboxes only in the first column.

I am not able to insert values with checkboxes at the second column of grid.
Am i missing something here. Pls help me in this.

Joan Murt at 26-Mar-11 5:06am
New solution posted... this one should do it for you ;)
Joan Murt at 26-Mar-11 4:52am
Perfect! I was getting my pc started in order to give you more pointers... answering anything from the phone is like... well a mini-nightmare... ;)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Ooops! I've just seen that you still had problems with putting checkboxes in the other columns...

Well you won’t be able to put checkboxes in the other columns without extra tweaking.
In order to keep things simple I’d go for some of the articles that are here regarding custom made CListCtrl derived controls. I would recommend you the article by Hans Dietrich[^] XListCtrl[^] which will allow you to do plenty of things.

Apart of that article, you can check[box] Roll eyes | :rolleyes: those ones also:

* allan Nielsen[^] SuperGrid - Yet Another listview control[^].

* Rolf Kristensen[^] CGridListCtrlEx - Grid Control Based on CListCtrl[^]

You'll notice that those Green Alien | [Alien] ians classes will make your life easier when it is time to work with a CListCtrl...

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

you have actually set extended style (LVS_EX_CHECKBOXES) to enable checkbox on mfc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 450
1 CPallini 320
2 F-ES Sitecore 240
3 Sergey Alexandrovich Kryukov 234
4 CHill60 220
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 28 Mar 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100