Search code examples
c#vb.netwinformsinfragistics

Changing the cell color in an ultragrid with the columns key and for each


My goal is to color the exactly same cell as i have already colored, but just one column before. I tried do it with the index but that didn't work out. I got a hint that i should do it with the Key property but i can't figure out how. Here is what i tried:

For Each column As UltraGridColumn In ugResult.DisplayLayout.Bands(0).Columns

                If column.Key = "K_Art" Or column.Key = "UANR" Or column.Key = "Ueberbegriff" Or column.Key = "Benennung" Or column.Key = "Anzahl" Or column.Key = "Einheit" Or column.Key = "Einzelkosten" Or column.Key = "Sumcode" Or column.Key = "Status" Then
                    Exit For
                Else
                    If e.Row.Cells(column.Key).Value IsNot Nothing Then

                        e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                        e.Row.Cells(column.Index - 1).Appearance.BackColor = Color.Yellow
                    End If

                End If
            Next

Any help in c# and vb.net is appreciated. Thank you


Solution

  • Here is my solution:

    For Each column As UltraGridColumn In ugResult.DisplayLayout.Bands(0).Columns
                    Select Case column.Key
                        Case "K_ArtCompare"
                            If e.Row.Cells(column.Key).Value IsNot Nothing Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("K_Art").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("K_Art").Value
                            End If
                        Case "UANR_Compare"
                            If e.Row.Cells(column.Key).Value IsNot Nothing Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("UANR").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("UANR").Value
                            End If
                        Case "UeberbegriffCompare"
                            If e.Row.Cells(column.Key).Value IsNot Nothing Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("Ueberbegriff").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("Ueberbegriff").Value
                            End If
                        Case "BenennungCompare"
                            If e.Row.Cells(column.Key).Value IsNot Nothing Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("Benennung").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("Benennung").Value
                            End If
                        Case "AnzahlCompare"
                            If e.Row.Cells(column.Key).Value <> -1 Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("Anzahl").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("Anzahl").Value
                            End If
                        Case "EinheitCompare"
                            If e.Row.Cells(column.Key).Value IsNot Nothing Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("Einheit").Appearance.BackColor = Color.Yellow
                            End If
                        Case "EinzelkostenCompare"
                            If e.Row.Cells(column.Key).Value <> -1 Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("Einzelkosten").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("Einzelkosten").Value
                            End If
                        Case "SummencodeCompare"
                            If e.Row.Cells(column.Key).Value IsNot Nothing Then
                                e.Row.Cells(column.Key).Appearance.BackColor = Color.Yellow
                                e.Row.Cells("Sumcode").Appearance.BackColor = Color.Yellow
                            Else
                                e.Row.Cells(column.Key).Value = e.Row.Cells("Sumcode").Value
                            End If
                    End Select
    
                Next
        End Select