I have a CListCtrl in a MFC dialog. What I have to do is disbling some the items based on a condition so that user can't select that.Till now I have changed the colour but thats not proper a solution. My code looks like this:
void CSomeDialog::OnCustomdrawElementList(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
*pResult = 0;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
COLORREF crText;
//Here I want to do disable based on some condition of the data related to the item//
if ( (pLVCD->nmcd.dwItemSpec % 2) == 0 )
crText = RGB(255,0,0);
else if ( (pLVCD->nmcd.dwItemSpec % 2) == 1 )
crText = RGB(0,255,0);
// Storing the color back
pLVCD->clrText = crText;
*pResult = CDRF_DODEFAULT;
}
}
I am unable to find any reference on how to disable a row yet.
Another problem , even after managing the disbling part how to get the data related to the item here in this custom draw function? can pLVCD->nmcd.lItemlParam be used to call GetItemData(). Please help.