C# 对于该列,使用这些值确定前3名,并将其着色。完美!这正是我所需要的,可以在多个对象中传递的东西。非常感谢。 For Each column As DataGridViewColumn In dgv.Columns If column.Visible =
C# 对于该列,使用这些值确定前3名,并将其着色。完美!这正是我所需要的,可以在多个对象中传递的东西。非常感谢。 For Each column As DataGridViewColumn In dgv.Columns If column.Visible =,c#,wpf,wpfdatagrid,colorize,C#,Wpf,Wpfdatagrid,Colorize,对于该列,使用这些值确定前3名,并将其着色。完美!这正是我所需要的,可以在多个对象中传递的东西。非常感谢。 For Each column As DataGridViewColumn In dgv.Columns If column.Visible = True Then Dim vals() As Object = GetDistinctValuesFromColumn(dgv, column.Index) Select Case column.ToolTipText.
对于该列,使用这些值确定前3名,并将其着色。完美!这正是我所需要的,可以在多个对象中传递的东西。非常感谢。
For Each column As DataGridViewColumn In dgv.Columns
If column.Visible = True Then
Dim vals() As Object = GetDistinctValuesFromColumn(dgv, column.Index)
Select Case column.ToolTipText.ToLower()
Case "d"
For Each row As DataGridViewRow In dgv.Rows
row.Cells(column.Index).Style.BackColor = dgv.Columns(column.Index).DefaultCellStyle.BackColor
Next
Dim lowCount As Integer = (vals.GetUpperBound(0) + 1) - 3
If lowCount < 0 Then lowCount = 0
For j As Integer = vals.GetUpperBound(0) To lowCount Step -1
For Each row As DataGridViewRow In dgv.Rows
If (Not (row.Cells(column.Index).FormattedValue Is DBNull.Value)) Then
If CStr(row.Cells(column.Index).FormattedValue) = CStr(String.Format("{0:n1}", vals(j))) Then
row.Cells(column.Index).Style.BackColor = colors(vals.GetUpperBound(0) - j)
End If
End If
Next
Next
Case "a"
' First de-colorize the row
For Each row As DataGridViewRow In dgv.Rows
row.Cells(column.Index).Style.BackColor = dgv.Columns(column.Index).DefaultCellStyle.BackColor
Next
Dim lowCount As Integer = 2
If lowCount > vals.GetUpperBound(0) Then lowCount = vals.GetUpperBound(0)
For j As Integer = 0 To lowCount
For Each row As DataGridViewRow In dgv.Rows
If (Not (row.Cells(column.Index).FormattedValue Is DBNull.Value)) Then
If CStr(row.Cells(column.Index).FormattedValue) = CStr(String.Format("{0:n1}", vals(j))) Then
row.Cells(column.Index).Style.BackColor = colors(j)
End If
End If
Next
Next
Case Else
' do nothing
End Select
' Copy the highlighting rules from the EGB box to the EGL box if we're on the dgv
If dgv.Name = "dgvRace" Then
For i As Integer = 0 To dgv.Rows.Count - 1
dgv.Rows(i).Cells("effGradeLetter").Style = dgv.Rows(i).Cells("effGradeLarge").Style
Next
End If
' Update all the tooltips for each box
Dim places() As String = {"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th"}
For Each row As DataGridViewRow In dgv.Rows
' Update tooltiptext for each row
Dim place As Integer = FindIndexInArray(vals, row.Cells(column.Index).FormattedValue)
If place > -1 Then
Dim placeStr As String = IIf(column.ToolTipText.ToLower() = "d", places(vals.GetUpperBound(0) - place), places(place))
'If column.ToolTipText.ToLower() = "d" Then place = vals.GetUpperBound(0) - place
row.Cells(column.Index).ToolTipText = String.Format("Column Place {0}", placeStr)
If row.Cells(column.Index).Value.GetType().ToString() = "System.Single" Or row.Cells(column.Index).Value.GetType().ToString() = "System.Int32" Then
' Get upper/lower difference if available
If place > 0 Then
Dim distFromPlaceBefore As Single = Math.Abs(CSng(vals(place)) - CSng(vals(place - 1)))
Dim distFromFirstPlace As Single = Math.Abs(CSng(vals(place)) - CSng(vals(0)))
row.Cells(column.Index).ToolTipText &= ControlChars.CrLf & String.Format(" - Distance from {0}: {1:n1}; Distance from 1st: {2:n1}", places(place - 1), distFromPlaceBefore, distFromFirstPlace)
End If
If place < vals.GetUpperBound(0) Then
Dim distFromPlaceAfter As Single = Math.Abs(Math.Round(CSng(vals(place)) - CSng(vals(place + 1)), 1))
Dim distFromLastPlace As Single = Math.Abs(Math.Round(CSng(vals(place)) - CSng(vals(vals.GetUpperBound(0))), 1))
row.Cells(column.Index).ToolTipText &= ControlChars.CrLf & String.Format(" - Distance from {0}: {1:n1}; Distance from {3}: {2:n1}", places(place + 1), distFromPlaceAfter, distFromLastPlace, places(vals.GetUpperBound(0)))
End If
End If
End If
Next
End If
Next