منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
[كود] تلوين نص في جدول البيانات - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : [كود] تلوين نص في جدول البيانات (/showthread.php?tid=46743)



تلوين نص في جدول البيانات - محمد مسافر - 15-08-23

سلامي للجميع 

عندي جدول البيانات DataGridView الموضح في الصوره المرتبط بقاعده بيانات اكسس اريد التمييز باللاوان للتقديرات حاولت وعملت على الاكود الموضحه في الصوره ومافي نتيجه فاين الاشكاليه


RE: تلوين نص في جدول البيانات - محمد مسافر - 15-08-23

في غلط في الكتابه


RE: تلوين نص في جدول البيانات - aljzazy - 16-08-23

استخدم حدث CellFormatting للداتا جرد فيو
مثال 
كود :
For Each MiColumna As DataGridViewRow In DataGridView 1.Rows

            If MiColumna.Cells(5).Value.ToString() = "FaceBook" Then
               MiColumna.DefaultCellStyle.BackColor = Color.White
               MiColumna.DefaultCellStyle.ForeColor = Color.Black
           ElseIf MiColumna.Cells(5).Value.ToString() = "" Then
               MiColumna.DefaultCellStyle.BackColor = Color.LightGreen
               MiColumna.DefaultCellStyle.ForeColor = Color.Black
           ElseIf MiColumna.Cells(5).Value.ToString() = "" Then
               MiColumna.DefaultCellStyle.BackColor = Color.LightGreen
               MiColumna.DefaultCellStyle.ForeColor = Color.Black
            ElseIf MiColumna.Cells(5).Value.ToString() = "" Then
               MiColumna.DefaultCellStyle.BackColor = Color.LightGreen
               MiColumna.DefaultCellStyle.ForeColor = Color.Black
            ElseIf MiColumna.Cells(5).Value.ToString() = "" Then
               MiColumna.DefaultCellStyle.BackColor = Color.LightGreen
               MiColumna.DefaultCellStyle.ForeColor = Color.Black
           Else
               MiColumna.DefaultCellStyle.BackColor = Color.White
               MiColumna.DefaultCellStyle.ForeColor = Color.Black
           End If
       Next
عدل على المثال كما تريد وضعه في الحدث الذي تكلمت عته


RE: تلوين نص في جدول البيانات - محمد مسافر - 16-08-23

الحمد لله جربت كود اخر والنتيجه تمام والشكر للاخ العزيز / aljzazy  الذي فتح لي طريق عن طريق الحدث CellFormatting


الكود للافاده
PHP كود :
Private Sub DataGridView1_CellFormatting(ByVal sender As ObjectByVal e As DataGridViewCellFormattingEventArgsHandles DataGridView1.CellFormatting
        
' تحديد العمود الذي ترغب في تلوين قيمه
        Dim targetColumnIndex As Integer = 5 ' 
تغيير القيمة حسب رقم العمود الخاص بك

        If e
.ColumnIndex targetColumnIndex AndAlso e.Value IsNot Nothing Then
            Dim cellValue 
As String e.Value.ToString()

 
           ' التحقق من القيمة وتعيين الألوان المناسبة
            If cellValue = "Facebook" Then
                e.CellStyle.BackColor = Color.Yellow
                e.CellStyle.ForeColor = Color.Black

            ElseIf cellValue = "Excellent" Then
                e.CellStyle.BackColor = Color.LightGreen
                e.CellStyle.ForeColor = Color.Black

            ElseIf cellValue = "Excellent" Then
                e.CellStyle.BackColor = Color.LightGreen
                e.CellStyle.ForeColor = Color.Black

            ElseIf cellValue = "Excellent" Then
                e.CellStyle.BackColor = Color.LightGreen
                e.CellStyle.ForeColor = Color.Black

            ElseIf cellValue = "Excellent" Then
                e.CellStyle.BackColor = Color.LightGreen
                e.CellStyle.ForeColor = Color.Black

            End If
            ' 
يمكنك إضافة المزيد من الشروط حسب احتياجاتك

            
' قم بتعيين القيمة المعدلة إلى الخلية
            e.Value = cellValue
        End If
    End Sub
End Class