Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the Backcolour of a Treeview 1

Status
Not open for further replies.

madlarry

Programmer
Dec 6, 2000
117
GB
Hi All,

Does anyone know how to change the backcolour of a Treeview?? I guess it might have to be an API call....?

Thanks,

Madlarry
 
Try adding this to your form...

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As _
Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd _
As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd _
As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Const GWL_STYLE = -16&
Const TVM_SETBKCOLOR = 4381&
Const TVS_HASLINES = 2&

Sub SetTreeViewBackColor(TV As TreeView, ByVal BackColor As Long)
Dim lStyle As Long
Dim TVNode As Node

' set the BackColor for every node
For Each TVNode In TV.Nodes
TVNode.BackColor = BackColor
Next

' set the BackColor for the TreeView's window
SendMessage TV.hwnd, TVM_SETBKCOLOR, 0, ByVal BackColor
' get the current style
lStyle = GetWindowLong(TV.hwnd, GWL_STYLE)
' temporary hide lines
SetWindowLong TV.hwnd, GWL_STYLE, lStyle And (Not TVS_HASLINES)
' redraw lines
SetWindowLong TV.hwnd, GWL_STYLE, lStyle
End Sub

Can't claim credit for this - got it from the VB2TheMAX site
Chaz
 
Thanks scorpio66,

That does the trick, however at runtime when I navigate down the tree parts of the screen in front of the node is still white (it's hard to describe but really strange!). I have tried a couple of other things but it still happens.

Beats me why Microsoft didn't put a standard Backcolor property into the Treeview's like every other control.

Cheers anyway,

Madlarry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top