On Sat, 19 Oct 2013 12:50:55 -0700 (PDT), George Tritsos
<
George...@yahoo.gr> wrote:
Hello George,
> I want to change the color of a specific item in a List View.
>
>e.g. 2nd line 1st column and 3rd line 1st column red color
>
>Is it possible?
>
Yes. First you will need the Common Control MEF (if you don't have
that somewhere, drop me a mail and I'll send it to you). After that it
will look something like this, in the ControlNotify of your LV. For a
so called iSubitem (= a column) I inspect the content and colour it
green or red.
METHOD ControlNotify(oEvent) CLASS ToDoExplorer
LOCAL pNMCustomDraw AS _WINNMLVCUSTOMDRAW
LOCAL dwDrawStage AS DWORD
LOCAL dwItem AS DWORD
LOCAL oItem AS ListViewItem
LOCAL dCode AS DWORD
dCode := oEvent:NotifyCode IF dCode = NM_CUSTOMDRAW .AND.
IsInstanceOf( oEvent:control, #LISTVIEW )
pNMCustomDraw := PTR( _CAST , oEvent:lParam )
dwDrawStage := pNMCustomDraw.nmcd.dwDrawStage
DO CASE
CASE dwDrawStage = CDDS_PREPAINT
SELF:EventReturnValue := CDRF_NOTIFYITEMDRAW
CASE _AND( dwDrawStage , CDDS_ITEMPREPAINT ) > 0
dwItem := pNMCustomDraw.nmcd.dwItemSpec
DO CASE
// dwItem contains the 0-based item
and
// pNMCustomDraw.iSubItem contains the
0-based subitem == column
CASE pNMCustomDraw.iSubItem==1
// 1 is my first column
oItem:=SELF:oLV:GetNextitem(LV_GNIBYITEM,,,,,dwItem)
pNMCustomDraw.clrText := DWORD(RGB( 0 , 0 , 0 )) // black
IF oItem:GetText( #DONE)=Vt(CLM_YES,"Yes")
pNMCustomDraw.clrTextBk := DWORD(RGB( 150 , 220 , 160 ) ) //
Light green
ELSE
pNMCustomDraw.clrTextBk := DWORD(RGB( 250 , 130 , 130 )) //l
Light red
ENDIF
ENDCASE
RETURN SELF:EventReturnValue
ENDIF
RETURN SUPER:ControlNotify( oEvent )
Dick