Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert CheckBoxes into CListBox

Status
Not open for further replies.

Huskey

Vendor
Aug 23, 2002
53
GB
Hi there,

Is there any way to insert the checkboxes into the CListBox. Let's say, I have 10 lines in the ClistBox. I would like to see each line has its own checkbox in front.

Look forward to your reply. Thank you

regards,

 
Hi,

Thanks for your reply Somebody has told me this before. But, how to use CChecklistbox. As far as I concern, the CChecklistbox is inherited from CListBox. I am sorry, my knowledge in Visual C++ is very limited. Please help! MAny thanks!
 
Hi

- Add a ListBox to your dialog box
- Modify its properties: in the 'Style' tab, select 'Owner Draw' as fixed and check 'Has Strings'
- Use class wizard to build a variable for the Listbox. Say you call it m_List
- Modify the m_List declaration like this:
CCheckListBox m_List;
- Add some code to populate the listbox:
m_List.AddString( "Item 0");
m_List.AddString( "Item 1");
m_List.AddString( "Item 2");
m_List.AddString( "Item 3");
- To get the checked item(s), use code like this:

for ( int nItem = 0; nItem < m_List.GetCount(); nItem++)
{
if ( m_List.GetCheck( nItem))
{
CString str;

str.Format( &quot;Item %d is Checked &quot;, nItem);

AfxMessageBox( str);
}
}

HTH

Thierry

BTW: read the doc for additional info about CCheckListBox class ...
 
Hi

Thanks very much for your help. I have finally fixed the problem with the help of your code. Many thanks. Have a good day! :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top