Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0 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;
GetWindowRect(&rectDummy);
DWORD dwStyle = LBS_NOINTEGRALHEIGHT | LVS_REPORT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
 
m_listGrid2.Create(dwStyle, rectDummy, this, IDC_LIST1);
m_listGrid2.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE | LVS_REPORT | DFCS_CHECKED , 0, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
 
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??
 
Shiva.
Posted 24-Mar-11 22:30pm
Edited 24-Mar-11 22:38pm
TweakBird17.1K
v2
Rate this: bad
good
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...
  Permalink  
Comments
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.
 
Shiva.
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
good
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...
 
HTH!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

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

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 329
2 CPallini 260
3 DamithSL 214
4 Maciej Los 197
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 28 Mar 2011
Copyright © CodeProject, 1999-2014
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