Does anybody have a piece of code how to change the Backcolor of a single cell or a complete row in a Listview in report mode?
Background:
I want to change the backcolor of a cell according to a status.
Row1 - Col Status has value 1 - cell backcolor = Green
Row2 - Col Status has value 2 - cell backcolor = Yellow
Row3 - Col Status has value 3 - cell backcolor = Red
Rolf
Rolf,
I'm currently updating my ListViewDemo to demonstrate how to change the Backcolor or ForeColor of a complete row (%WM_NOTIFY message).
It will be ready in 5 minutes.
Jean-Pierre
Great - thanks for the quick response, Jean-Pierre.
Rolf
Rolf,
You've to answer to the WM_NOTIFY message inside the CUSTOM handler of the form that contains the ListView control.
'--------------------------------------------------------------------------------
' 7. ... change the Backcolor or ForeColor of a complete row (%WM_NOTIFY message)
'--------------------------------------------------------------------------------
Case %WM_NOTIFY
Local lpNmh As NMHDR Ptr
Local lpLvNm As NM_LISTVIEW Ptr
Local lpLvCd As NMLVCUSTOMDRAW Ptr
Local lRow As Long
Local lCol As Long
lpNmh = lParam
If @lpNmh.idFrom = IDC_FORM1_LISTVIEW1 Then
lpLvNm = lParam
Select Case @LpLvNm.hdr.Code
Case %NM_CUSTOMDRAW
lpLvCd = lParam
Select Case @lplvcd.nmcd.dwDrawStage
Case %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
Function = %CDRF_NOTIFYSUBITEMDRAW
Case %CDDS_ITEMPREPAINT Or %CDDS_SUBITEM
' to retrieve the line and column number of the cell
lRow = @lpLvCd.nmcd.dwItemSpec ' Line number
lCol = @lpLvCd.iSubItem ' Column number
' for demonstration purpose => should be adapted for your needs
Select Case lRow Mod 3
Case 0
'@lpLvCd.clrTextBk = &H0000FF00
@lpLvCd.clrText = &H0000FF00 ' green text
Case 1
'@lpLvCd.clrTextBk = &H000000FF
@lpLvCd.clrText = &H000000FF ' red text
Case 2
@lpLvCd.clrTextBk = &H00D8E9EC ' grey backcolor
'@lpLvCd.clrText = &H000000FF
End Select
Function = %CDRF_NEWFONT
End Select
End Select
End If ' If @lpNmh.idFrom = IDC_FORM1_LISTVIEW1 Then
Jean-Pierre
Thanks a lot, Jean-Pierre, I am gonna try it out right now.
Rolf
Rolf,
I've just updated the ListViewDemo http://www.planetsquires.com/protect/forum/index.php?topic=2026.0
to show how to : 7. ... change the Backcolor or ForeColor of a complete row (%WM_NOTIFY message) *** NEW 11/14/2009 ***
So it could be easier to have a look at the complete project; tell me if you have any question.
Jean-Pierre