Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have created one listcontrol in dialogbox. and i have used drawitem method to change the selection color of the selected item color to red. this work fine but problem is when i click the last item and then click the any upper one the last item has alway stay highlighted.for exp assume i have 4 item in list and i have clicked the 4th item the 3rd then 2nd .so all this item are highlighted. so how to select only one or two item ....

My code is like this..

void ClstCustmDraw::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect(lpDrawItemStruct->rcItem);
int row= lpDrawItemStruct->itemID;

LVITEM lvi;
lvi.mask=LVIF_STATE;
lvi.iItem=row;
lvi.iSubItem=0;
lvi.stateMask=LVIS_SELECTED;
GetItem(&lvi);

if(lvi.state & LVIS_SELECTED)
{
pDC->SetBkColor(RGB(255,0,0));
}

/*LVCOLUMN lvc;
lvc.mask=LVCF_FMT | LVCF_WIDTH;*/

CRect CellRect(rect);
CellRect.right=CellRect.left;

for(int col=0;col<2;++col)
{

CellRect.left=CellRect.right;
CellRect.right=CellRect.right+180;
pDC->FillSolidRect(CellRect,pDC->GetBkColor());

// lvi.iSubItem=col;
// GetItem(&lvi);

CString str=GetItemText(row,col);
pDC->DrawText(str,-1,CellRect,DT_TOP);


}

Thanks...
Posted

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900