Have I missed something in the listview properties window, but I would like to change the colour of the grid lines.
Thanks.
Hi Mark,
I don't think that there is any standard way to change the color of the lines. You may have to switch to a 3rd party grid like My Little Grid by James Klutho http://psoftsol.com/mlg.html
I am working on an example now that will intercept %WM_PAINT and change the colors for you. I'll post the code here in a few minutes.
Okay. Here it is.
'--------------------------------------------------------------------------------
Function FORM1_LISTVIEW1_CUSTOM ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Local rc As Rect
Local hWndHeader As Dword
Local nTop As Long
Local nWidth As Long
Local nHeight As Long
Local nColumnCount As Long
Local nBorderX As Long
Local i As Long
Local hDC As Dword
Local hdItem As HD_ITEM
Local ff As FLY_DATA Ptr
Local hPen As Long
Select Case wMsg
Case %WM_PAINT
'// First Let the Control Do its Default drawing.
If hWndControl Then
ff = GetProp(hWndControl, "FLY_PTR")
CallWindowProc @ff.OldProc, hWndControl, wMsg, wParam, lParam
End If
'// Draw the Lines only For LVS_REPORT mode
If( (GetWindowLong(hWndControl, %GWL_STYLE) And %LVS_TYPEMASK) = %LVS_REPORT ) Then
'// If no items in the Listview then simply exit
If ListView_GetItemCount( hWndControl ) = 0 Then Exit Function
'// Set the extended gridlines style to help displaying the lines properly
If (ListView_GetExtendedListViewStyle(hWndControl) And %LVS_EX_GRIDLINES) = 0 Then
ListView_SetExtendedListViewStyle hWndControl, (ListView_GetExtendedListViewStyle(hWndControl) Or %LVS_EX_GRIDLINES)
End If
hDC = GetDC( hWndControl )
' Save the DC attributes so we can quickly restore them later
SaveDC hDC
'// Set the ForeColor of the lines that we want to paint. We do this
'// by creating a pen.
hPen = CreatePen( %PS_SOLID, 1, %Red ) ' could use RGB() color as well
SelectObject hDC, hPen
'// Get the number Of columns
hWndHeader = SendMessage( hWndControl, %LVM_GETHEADER, 0, 0 )
nColumnCount = SendMessage( hWndHeader, %HDM_GETITEMCOUNT, 0, 0 )
'// The bottom Of the header corresponds To the top Of the Line
GetClientRect hWndHeader, rc
nTop = rc.nBottom
'// Now Get the Client Rect so we know the Line length And
'// when To Stop
GetClientRect hWndControl, rc
'// The Border Of the column Is offset by the horz scroll
nBorderX = 0 - GetScrollPos( hWndControl, %SB_HORZ )
For i = 0 To nColumnCount - 1
'// Get the Next Border
hdItem.mask = %HDI_WIDTH
SendMessage hWndHeader, %HDM_GETITEM, i, VarPtr(hdItem)
nBorderX = nBorderX + hdItem.cxy
'// If Next Border Is outside Client area, Break Out
If nBorderX >= rc.nRight Then Exit For
'// Draw the Line.
MoveTo hDC, nBorderX-1, nTop
LineTo hDC, nBorderX-1, rc.nBottom
Next
'// Draw the horizontal grid Lines
'// First Get the height (if no rows exist then use the Header's height)
If ListView_GetItemRect( hWndControl, 0, rc, %LVIR_BOUNDS ) Then
nHeight = rc.nBottom - rc.nTop
GetClientRect hWndControl, rc
nWidth = rc.nRight
For i = 1 To ListView_GetCountPerPage(hWndControl)
MoveTo hDC, 0, nTop + nHeight*i
LineTo hDC, nWidth, nTop + nHeight*i
Next
End If
RestoreDC hDC, -1
ReleaseDC hWndControl, hDC
End If
Function = %TRUE
End Select
End Function
Thanks Paul Awaiting FF3
Paul, I am trying to use your example but getting an error that related to this pointer. "FLY_DATA Ptr". Where can I define or locate "FLY_DATA"?
Sorry Andy, I must have used FF3 to make that example. Try changing the FLY_ prefix to be FF_ instead. That should fix the problem.