Hi,
Guys, please help me, I need your help. I wanted to identify the conflicted schedule of each of the section. If there’s conflict then the two or more subjects that are conflict will be colored to make then noticeable. They are in datagridview. I don’t know what’s wrong but there are some that although they are conflict they are not highlighted. Here’s my code:

For item As Integer = 0 To DataGridClass.RowCount - 1
            For item2 As Integer = 0 To DataGridClass.RowCount - 1
                If DataGridClass.Rows(item).Cells(ClassID).Value <> DataGridClass.Rows(item2).Cells(ClassID).Value And DataGridClass.Rows(item).Cells(Section).Value = DataGridClass.Rows(item2).Cells(Section).Value And DataGridClass.Rows(item).Cells(Day).Value = DataGridClass.Rows(item2).Cells(Day).Value And (DataGridClass.Rows(item).Cells(TimeStart).Value >= DataGridClass.Rows(item2).Cells(TimeStart).Value And DataGridClass.Rows(item).Cells(TimeEnd).Value <= DataGridClass.Rows(item2).Cells(TimeEnd).Value) Then
                    DataGridClass.Rows(item).DefaultCellStyle.BackColor = Color.Aquamarine
                    DataGridClass.Rows(item2).DefaultCellStyle.BackColor = Color.Aquamarine
                End If
                item2 = item2 + 1
            Next
            item = item + 1
        Next

I used a DGV with 3 columns for this, hope it helps.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        setHighLightsForConflicts(DataGridView1)
    End Sub
    Sub setHighLightsForConflicts(ByVal selDGV As DataGridView)
        With selDGV
            Dim s1, s2 As String, chrMain As Char : s1 = "" : s2 = s1 : chrMain = "|"
            For i As Integer = 0 To .RowCount - 1 '// loop thru all rows.
                With .Rows(i)
                    s1 = .Cells(0).Value & chrMain & .Cells(1).Value & chrMain & .Cells(2).Value '// store the row's value, easier to manage and compare to other rows.
                End With
                If Not i + 1 = .RowCount Then '// check if next item to check exists.
                    For x As Integer = i + 1 To .RowCount - 1 '// loop thru all items following the s1.Item.
                        With .Rows(x)
                            s2 = .Cells(0).Value & chrMain & .Cells(1).Value & chrMain & .Cells(2).Value '// set value.
                            If s1 = s2 Then '// compare and get results.
                                .DefaultCellStyle.BackColor = Color.Aquamarine
                                selDGV.Rows(i).DefaultCellStyle.BackColor = Color.Aquamarine
                            End If
                        End With
                    Next
                End If
            Next
        End With
    End Sub
Comments
Your great!continue sharing your knowledge...and i will be back for more questions if you don't mind..hehe:D..thanks again!

@codeorder.....thanks a lot. Yes, it worked. The Schedules with the same/conflicts were highlighted already. But my problem now is...How about the in-between conflicts? I mean for example: i have a schedule on Monday 7 to 8:30am, but if i have another schedule on Monday, this time 8 to 9:30am, i want them to be highlighted too....That's my biggest problem...if you could help me i will be forever thanking you....Please...:D...if i can't pay you God will a thousandfold. Thanks so Much!

Hey...i got it!!thank you so much!!!I was able to highlight what i call the in-between conflicts of all the subjects...all thanks to you codeorder!!! Please continue sharing your knowledge...God speed!!!A million thanks!!

>>if you could help me i will be forever thanking you.
S.O.B., I missed out on the eternal.Thanks?:(
>>Please continue sharing your knowledge...God speed!!!
Just to get all biblical, I have no knowledge that God does not have, for I am one of his kids.

Everything else, glad I could help.:)

Edited 4 Years Ago by codeorder: &quot;I am his&quot; and &quot;being one of his kids&quot; is not the same; blame Bud-Light for the edit, or thank them.:)

This question has already been answered. Start a new discussion instead.