PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Douglas McDonald on July 08, 2011, 01:30:32 PM

Title: Listview text color
Post by: Douglas McDonald on July 08, 2011, 01:30:32 PM
I've been searching the form and found some code by Jean-Pierre that changed the text color for each row using  FORM1_WM_NOTIFY. My problem is I'm too stupid to figure out how to to this row by row as needed. I'm missing something very basic here I think.

For example:

FF_ListView_InsertItem( HWND_MAIN_LISTVIEW1, 0, 0, "Item1")
if some condition then change text color
FF_ListView_InsertItem( HWND_MAIN_LISTVIEW1, 1, 0, "Item2")
if some condition then change text color
FF_ListView_InsertItem( HWND_MAIN_LISTVIEW1, 2, 0, "Item3")

just to refresh, Jean-Pierre's code follows:
Function FORM1_WM_NOTIFY ( _
                         hWndForm     As Dword,     _  ' handle of Form
                         idCtrl       As Dword,     _  ' control ID
                         ByVal pNMHDR As NMHDR Ptr  _  ' pointer to NMHDR structure
                         ) As Long

    Local lpLvCd As NMLVCUSTOMDRAW Ptr
       
    Local lRow  As Long
    Local lCol  As Long

    ' if we are on the right control           
    If @pNMHDR.idFrom = IDC_FORM1_LISTVIEW1 Then       
                     
        Select Case @pNMHDR.Code
         
            Case %NM_CUSTOMDRAW
           
                lpLvCd = pNMHDR                   
                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.clrText = &H0000FF00  ' green text                           
                            Case 1
                                @lpLvCd.clrText = &H000000FF  ' red text                     
                             Case 2
                                @lpLvCd.clrTextBk = &H00D8E9EC  ' grey backcolor
                        End Select
                        Function = %CDRF_NEWFONT
                                                   
                End Select
   
         End Select
   
    End If  ' If @pNMHDR.idFrom = IDC_FORM1_LISTVIEW1 Then                                 

End Function
Title: Re: Listview text color
Post by: Paul Squires on July 08, 2011, 02:19:13 PM
Did you remember to check the WindowStyle "LVS_OWNERDRAWFIXED" for the ListView?
Title: Re: Listview text color
Post by: Douglas McDonald on July 08, 2011, 04:00:48 PM
I guess I didn't explain it correctly. The code works ok as it colors the text. The problem I have is I need to be able to choose when a row has a change in text color. I can't seem to do that in the MAIN_WM_NOTIFY.
What I'm trying to do is select a color, fill in a row, maybe select a different color for X number of rows ect.....

Thanks