Click here to Skip to main content
15,847,427 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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??

Updated 24-Mar-11 22:38pm

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...
Share this answer
Shiva S.S 26-Mar-11 0:20am    
Thank you so much Joan. I got it.
Shiva S.S 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 M 26-Mar-11 5:06am    
New solution posted... this one should do it for you ;)
Joan M 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... ;)
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] :rolleyes: those ones also:

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

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

You'll notice that those :bob:ians classes will make your life easier when it is time to work with a CListCtrl...

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900