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

Time:11-05

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

CodePudding user response:

I think this will work:

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.Index).Appearance.BackColor = Color.Yellow
                e.Row.Cells(column.Index - 1).Appearance.BackColor = Color.Yellow
         End If
     End If
Next

CodePudding user response:

You should compare the value of the cell with DbNull.Value like this:

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 Not DbNull.Value.Equals(e.Row.Cells(column.Key).Value) 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
  • Related