visual-c++checkboxclistctrlvisual-c++-2005

How to add checkboxes in multiple columns in VC++


I am new to the Visual C++, I am using Visual C++ 2005, I want to show some records in report where I am using ListControl. My single entry of records contains two boolean fields so that each row in the ListControl are to be represented with the Check boxes. In short there will be two checkboxes in each row. I used the ListControl but I found that there comes only one checkbox for each entry. So can anybody please explain how I can add multiple columns of checkboxes in ListControl, also what other classes I can use for doing same thing in visual C++. I implemented InitDialog as:

BOOL MyRecords::OnInitDialog()
{
    CDialog::OnInitDialog();

    m_listCtrl.SetExtendedStyle(LVS_EX_CHECKBOXES);
    m_listCtrl.InsertColumn(1,"First-Bool");
    m_listCtrl.SetColumnWidth(0, 70);

    UInt16 i = 0;
    CString pcid;

    for ( ; i <= 503; i++) {
        pcid.Format(_T("%d"), i);
        m_listCtrl.InsertItem(i, pcid);
    }

    return true;
}

Solution

  • CListCtrl class with report view will allow you to add checkboxes only in the first column. To add checkboxes in the multiple columns you have to derive the CListCtrl of your own and you have do it by your own. Here are the few examples which may help you:

    1. http://www.codeproject.com/Articles/29064/CGridListCtrlEx-Grid-Control-Based-on-CListCtrl
    2. http://www.codeproject.com/Articles/1796/XListCtrl-A-custom-draw-list-control-with-subitem
    3. http://www.codeproject.com/Articles/8112/CQuickList