使用列键和每个更改超网格中的单元格颜色
Changing the cell color in an ultragrid with the columns key and for each
我的目标是为与我已经着色的完全相同的单元格着色,但只是之前的一列。我试着用索引来做,但没有成功。我得到一个提示,我应该使用 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 的任何帮助表示赞赏。谢谢
我认为这会起作用:
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
您应该将单元格的值与 DbNull.Value
进行比较,如下所示:
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
这是我的解决方案:
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
我的目标是为与我已经着色的完全相同的单元格着色,但只是之前的一列。我试着用索引来做,但没有成功。我得到一个提示,我应该使用 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 的任何帮助表示赞赏。谢谢
我认为这会起作用:
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
您应该将单元格的值与 DbNull.Value
进行比较,如下所示:
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
这是我的解决方案:
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