首页 > 解决方案 > 使用 columns 键和为每个更改超网格中的单元格颜色

问题描述

我的目标是为我已经着色的完全相同的单元格着色,但之前只有一列。我试着用索引来做,但没有成功。我得到一个提示,我应该用 Key 属性来做,但我不知道怎么做。这是我尝试过的:

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

对 c# 和 vb.net 的任何帮助表示赞赏。谢谢

标签: c#vb.netwinformsinfragistics

解决方案


这是我的解决方案:

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

推荐阅读