الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف يمكن تغيير forecolor خاص ب Node في TreeView بناء على قيمة في جدول تكوين الTreeview

مغلقمُجاب
بدأه asiliem في 25 فبراير 2013 · 4 رد · 829 مشاهدة · في قواعد بيانات Microsoft Access
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

 

الأخوة الأعزاء

أعمل على قاعدة بيانات لبرنامج إدارة الجودة واستخدم الـ 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
 

ولكن لا يطبق غير قيمة واحدة فقط في جميع الاحوال

برجاء المساعدة وأشكركم مقدماً على سرعة الرد
 

post-27330-1206946370.gif

.

.

مدمن بحر العلم بالمنتدى

#2

اخي الفاضل

 

جرب استخدام خاصية  الألوان بهذه الطريقة :

 

 

If rs!NODE_COLOUR = 1 Thennodthis.Forecolor = vbRed
 
vbBlack
vbRed
vbGreen
vbYellow
vbBlue
vbMagenta
vbCyan
vbWhite
 
او بهذه الطريقة
 
If rs!NODE_COLOUR = 1 Then
nodthis.Forecolor = RGB (255,0,0)   ' RED Color
 
او
If rs!NODE_COLOUR = 1 Then
nodthis.Forecolor = RGB (0,255,0)   ' Green Color
 
او
If rs!NODE_COLOUR = 1 Then
nodthis.Forecolor = RGB (0,0,255)   ' Blue Color
 
 
 
اذا تمت الإجابه على السؤال فلا تنسى الضغط على ( أفضل إجابة )
 
 

بالتوفيق

تم تعديل هذه المشاركة بواسطة zahrah في 25 فبراير 2013 في 16:31

#3

أشكرك اخت زهرة على ردك السريع، بارك الله لك في علمك

 

ولكن المشكلة ليست في تحديد أو اختيار اللون

 

فكما تلاحظين من الكود أن هناك في جدول تكوين ال Treeview يوجد عمود Node_colour لكل Node في الكود السابق ومع تجربة الأكواد من طرفك تعطي نفس النتيجة، فهي تقوم بتلوين كل النقاط بنفس اللون

 

ما أبحث عنه هو تلوين كل node بلون مختلف وفق القيمة المتوفرة في حقل Node_colour في الصف المكون لهذه الـ Node، كما احاول أن أستخدم هذه الخاصية إن نجحت في تغيير اللون بناء على حقل من جدول آخر، ويمكن استخدام ذلك في التنبيهات مما يعطي الشجرة صورة أكثر تفاعلية.

 

post-27330-1206946370.gif

.

.

مدمن بحر العلم بالمنتدى

#4

شكراً للأخت زهرة
وشكرة لكل من حاول المساعدة

 

الحمد لله قمت بالتعديل على الكود ووجدت الحل على الرغم من محاولتي لأكثر من يومين، الكود كالتالي:

 

            With TreeView1.Nodes.Add(getNodeIndex(!NODE_FATHER_CODE), tvwChild, strKey, (!NODE_CODE) & ":" & !NODE_NAME_A)
                If rs!NODE_COLOUR = 0 Then
                    .Forecolor = QBColor(0)
                Else
                    If rs!NODE_COLOUR = 1 Then
                        .Forecolor = QBColor(1)
                    Else
                        If rs!NODE_COLOUR = 2 Then
                            .Forecolor = QBColor(2)
                        Else
                            If rs!NODE_COLOUR = 3 Then
                                .Forecolor = QBColor(3)
                           Else
                                If rs!NODE_COLOUR = 4 Then
                                    .Forecolor = QBColor(4)
                                Else
                                    If rs!NODE_COLOUR = 5 Then
                                        .Forecolor = QBColor(5)
                                    Else
                                        If rs!NODE_COLOUR = 6 Then
                                            .Forecolor = QBColor(6)
                                       Else
                                            If rs!NODE_COLOUR = 7 Then
                                                .Forecolor = QBColor(7)
                                            Else
                                                If rs!NODE_COLOUR = 8 Then
                                                    .Forecolor = QBColor(8)
                                                Else
                                                    If rs!NODE_COLOUR = 9 Then
                                                        .Forecolor = QBColor(9)
                                                    Else
                                                        If rs!NODE_COLOUR = 10 Then
                                                            .Forecolor = QBColor(10)
                                                        Else
                                                            If rs!NODE_COLOUR = 11 Then
                                                                .Forecolor = QBColor(11)
                                                            Else
                                                                If rs!NODE_COLOUR = 12 Then
                                                                    .Forecolor = QBColor(12)
                                                                Else
                                                                    If rs!NODE_COLOUR = 13 Then
                                                                        .Forecolor = QBColor(13)
                                                                    Else
                                                                        If rs!NODE_COLOUR = 14 Then
                                                                            .Forecolor = QBColor(14)
                                                                        Else
                                                                            If rs!NODE_COLOUR = 15 Then
                                                                                .Forecolor = QBColor(15)
                                                                            End If
                                                                        End If
                                                                    End If
                                                                End If
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End With

 


ولكن هل يمكن إختصار الكود بواسطة FOR NEXT STATEMENT ؟

post-27330-1206946370.gif

.

.

مدمن بحر العلم بالمنتدى

#5 أفضل إجابة

اخي الفاضل

 

جرب احدى هذه الحلول 

 

 

Dim i As Integer
For i = 0 To 15
With TreeView1.Nodes.Add(getNodeIndex(!NODE_FATHER_CODE), tvwChild, strKey, (!NODE_CODE) & ":" & !NODE_NAME_A)
                If rs!NODE_COLOUR = i Then
                    .Forecolor = QBColor(i)
                end if
      End With
Next i
 
 
او 
 
Dim i as Integer
i=0
Do Until rs.EOF
With TreeView1.Nodes.Add(getNodeIndex(!NODE_FATHER_CODE), tvwChild, strKey, (!NODE_CODE) & ":" & !NODE_NAME_A)
                If rs!NODE_COLOUR = i Then
                    .Forecolor = QBColor(i)
                 end if
         End With
   rs.MoveNext
Loop
rs.Close
Set rs = Nothing
 
بالتوفيق

تم تعديل هذه المشاركة بواسطة zahrah في 26 فبراير 2013 في 10:56

−1

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…