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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can anybody help me please...I'm a beginner

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Could you please take a look on these code and tell me where is the mistake. When I click on a Node and it expands, some white boxes appears and I don't know how to solve the problem.
I'm sorry, but I'm new on vb ......:)
'API Call for Sending the message
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal _
wParam As Long, lParam As Long) As Long

'Constants for changing the treeview
Private Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&
Private Const TV_FIRST As Long = &H1100
Private Const TVM_GETTEXTCOLOR As Long = (TV_FIRST + 32)
Private Const TVM_SETTEXTCOLOR As Long = (TV_FIRST + 30)

Private Sub Form_Load()
'This is last weeks code
'Declare Variables
Dim mNode As Node
Dim i As Integer
'Populate the list box
'Add the primary node
Set mNode = TreeView1.Nodes.Add(, , "Abuelo", "abuelo")

Set mNode = TreeView1.Nodes.Add("Abuelo", tvwChild, "Papa", "papa")
mNode.EnsureVisible
Set mNode = TreeView1.Nodes.Add("Papa", tvwChild, "Nieto1", "nieto1")
Set mNode = TreeView1.Nodes.Add("Papa", tvwChild, "Nieto2", "nieto2")
Set mNode = TreeView1.Nodes.Add("Nieto1", tvwChild, "Bisnieto", "bisnieto1")

For Each mNode In TreeView1.Nodes
mNode.BackColor = RGB(255, 0, 0) 'blau fosc
Next

'This is this weeks code
'Send a message to the treeview telling it to
'change the background It uses an RGB colour setting
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
'Same as above except this one tells it to change
'the text colour
'Call SendMessage(TreeView1.hWnd, TVM_SETTEXTCOLOR, 0, ByVal RGB(255, 0, 0))
End Sub


Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim itmX As ListItem
If Node.Index <> 1 Then
If Node.Expanded = True Then
' Contrau el Node
Node.Expanded = False
Else: Node.Expanded = True 'Expandeix el Node
End If
End If
End Sub

 
'How to Change the TreeView Control Background Color
'===================================================

Option Explicit

Private Declare Function SendMessage Lib &quot;User32&quot; _
Alias &quot;SendMessageA&quot; _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) As Long

Private Declare Function GetWindowLong Lib &quot;User32&quot; _
Alias &quot;GetWindowLongA&quot; _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib &quot;User32&quot; _
Alias &quot;SetWindowLongA&quot; _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&

Dim frmlastForm As Form

Private Sub Form_Load()
Dim nodX As Node
Set nodX = TreeView1.Nodes.Add(, , &quot;R&quot;, &quot;Root&quot;)
Set nodX = TreeView1.Nodes.Add(&quot;R&quot;, tvwChild, &quot;C1&quot;, &quot;Child 1&quot;)
Set nodX = TreeView1.Nodes.Add(&quot;R&quot;, tvwChild, &quot;C2&quot;, &quot;Child 2&quot;)
Set nodX = TreeView1.Nodes.Add(&quot;R&quot;, tvwChild, &quot;C3&quot;, &quot;Child 3&quot;)
Set nodX = TreeView1.Nodes.Add(&quot;R&quot;, tvwChild, &quot;C4&quot;, &quot;Child 4&quot;)
nodX.EnsureVisible
TreeView1.Style = tvwTreelinesText ' Style 4.
TreeView1.BorderStyle = vbFixedSingle

End Sub

Private Sub Command1_Click()
Dim lngStyle As Long
Call SendMessage(TreeView1.hWnd, _
TVM_SETBKCOLOR, _
0, _
ByVal RGB(255, 0, 0)) 'Change the background
'color to red

' Now reset the style so that the tree lines appear properly
lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
Call SetWindowLong(TreeView1.hWnd, _
GWL_STYLE, _
lngStyle - TVS_HASLINES)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
End Sub

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top