我终于成功地通过以下方式做到了!
- you need to handle two events:
GridView.CellValueChanged
GridView.CustomDrawCell
- 您需要跟踪每个更改的单元格的索引。所以,我们需要一个List
创建一个类和其中的三个字段。
Public Class UpdatedCell
'UC means UpdatedCll
Public Property UCFocusedRow As Integer
Public Property UCFocusedColumnIndex As Integer
Public Property UCFieldName As String
Public Sub New()
UCFocusedRow = -1
UCFocusedColumnIndex = -1
UCFieldName = String.Empty
End Sub
End Class
初始化您的列表Form1_Load
功能。
Public lst As List(Of UpdatedCell) = New List(Of UpdatedCell)()
Now, in GridView.CellValueChanged
事件,执行以下操作:
Private Sub grdView_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs)
Dim currCell As New UpdatedCell
currCell.UCFocusedRow = e.RowHandle
currCell.UCFocusedColumnIndex = e.Column.AbsoluteIndex
currCell.UCFieldName = e.Column.FieldName
lst.Add(currCell)
End Sub
现在,执行以下操作GridView.CustomDrawCell
event:
Private Sub grdView_CustomDrawCell(sender As Object, e As RowCellCustomDrawEventArgs)
Dim prevColor As Color = e.Appearance.BackColor
For Each c As UpdatedCell In lst
If e.RowHandle = c.UCFocusedRow And
e.Column.AbsoluteIndex = c.UCFocusedColumnIndex And
e.Column.FieldName = c.UCFieldName Then
e.Appearance.BackColor = Color.Yellow
Else
If Not e.Appearance.BackColor = Color.Yellow Then
e.Appearance.BackColor = prevColor
End If
End If
Next
End Sub
请注意该参数e As RowCellCustomDrawEventArgs
包含所有必需的信息。我们只需要关心编辑后的单元格索引,因为GridView.CustomDrawCell
每次行/列焦点更改时调用。
查看结果。
Before
And After
NOTE黄色单元格具有不同的值,我使用内联/就地编辑器更改了这些值。
Thanks