السلام عليكم
الأخوة الأعزاء
أعمل على قاعدة بيانات لبرنامج إدارة الجودة واستخدم الـ treeview كأداة في الشاشة الرئيسية، واحتاج لتغيير لون الـ Node بناء على قيمة موجودة في جدول تكوين الشجرة أو من جدول آخر مرتبط
الكود عندي كالتالي:
Private Sub Form_Load()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strKey As String
Dim nodthis As MSComctlLib.Node
mstrFormArgs = ""
Set db = CurrentDb
Set rs = db.OpenRecordset( _
"SELECT * " & _
"FROM qlt_Switchboard " & _
"ORDER BY NODE_CODE,NODE_FATHER_CODE, NODE_CODE_sun", dbOpenSnapshot, dbReadOnly Or dbForwardOnly)
With rs
While Not .EOF
strKey = !NODE_CODE & ";" & Nz(!NODE_OBJECT_TYPE) & ";" & Nz(!NODE_OBJECT_NAME) & ";" & Nz(!NODE_FATHER_CODE) ' & ";" & Nz(!NODE_COLOUR)
For Each nodthis In Me.TreeView1.Nodes
If rs!NODE_COLOUR = 1 Then
nodthis.Forecolor = QBColor(1)
Else
If rs!NODE_COLOUR = 2 Then
nodthis.Forecolor = QBColor(2)
Else
If rs!NODE_COLOUR = 3 Then
nodthis.Forecolor = QBColor(3)
Else
If rs!NODE_COLOUR = 4 Then
nodthis.Forecolor = QBColor(4)
Else
If rs!NODE_COLOUR = 5 Then
nodthis.Forecolor = QBColor(1)
End If
End If
End If
End If
End If
Next nodthis
If !NODE_FATHER_CODE > 0 Then
'This node is a child-node of some other node;
'Find the parent node and add it below that node's last child
Me.TreeView1.Nodes.Add getNodeIndex(!NODE_FATHER_CODE), tvwChild, strKey, (!NODE_CODE) & "-" & !NODE_NAME_A
' TreeView1.Nodes.Add (getNodeIndex:=RS!NODE_FATHER_CODE, Relationship:=tvwChild, !NODE_CODE) & ":" & !NODE_NAME_A
' .forcolor = vbRed
Else
'There is no parent - add this node to the treeview's root
Me.TreeView1.Nodes.Add , tvwLast, strKey, (!NODE_CODE) & "-" & !NODE_NAME_A
End If
.MoveNext
Wend
End With
End Subأريد تغيير لون النود بناء على قيمة موجودة في حقل node_colour في جدول qlt_switchboard
حاولت بإستخدام:
If rs!NODE_COLOUR = 1 Then
nodthis.Forecolor = QBColor(1)
Else
If rs!NODE_COLOUR = 2 Then
nodthis.Forecolor = QBColor(2)
Else
If rs!NODE_COLOUR = 3 Then
nodthis.Forecolor = QBColor(3)
Else
If rs!NODE_COLOUR = 4 Then
nodthis.Forecolor = QBColor(4)
Else
If rs!NODE_COLOUR = 5 Then
nodthis.Forecolor = QBColor(1)
End If
End If
End If
End If
End If
ولكن لا يطبق غير قيمة واحدة فقط في جميع الاحوال
برجاء المساعدة وأشكركم مقدماً على سرعة الرد


