lundi 5 août 2019

How do we add Checkboxes for an ownerdrawn list control in MFC?

How can I make an owner-draw list control with checkboxes. What I need is: I have data separate, each has a different color code. I need to add this to a list control with the format : This allows multiple selection [checkbox] [color code rectangle] Text_Item I need to use checkboxes to select which I want selected. I Should be able to select multiple items from listcontrol without having to use CTRL+Click.

I have tried using DrawFrameControl For getting the checkboxes.But using which we are able to select only one item at a time.Following is my code I have used in my drawitem method.

void OwnerdrawListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) {

       bool sel = (lpDrawItemStruct->itemState && ODS_SELECTED);
       if
             DrawFrameControl(*pDC, rcItem, DFC_BUTTON, DFCS_CHECKED);
       else
             DrawFrameControl(*pDC, rcItem, DFC_BUTTON, DFCS_INACTIVE);

}

This is how I am adding the checkboxes to my listCtrl.Im handling an NM_Click event in which Im setting the state of the ienter code heretem that is being clicked.




Aucun commentaire:

Enregistrer un commentaire