Private Sub GridView1_RowCellStyle(sender As Object, e As
RowCellStyleEventArgs) Handles GridView1.RowCellStyle
Try
If IsDBNull(e.CellValue) Then
e.Appearance.BackColor = Color.LightYellow
End If
Dim selectedCells As GridCell() = GridView1.GetSelectedCells()
isRowSelected = GridView1.IsRowSelected(e.RowHandle)
For Each Cells In selectedCells
If GridView1.GetSelectedCells.Count = 1 Then
If IsDBNull(GridView1.GetRowCellValue(Cells.RowHandle,
Cells.Column)) Then
e.Appearance.BackColor = Color.LightYellow
End If
Else
If isRowSelected Then
If IsDBNull(GridView1.GetRowCellValue(Cells.RowHandle,
Cells.Column)) Then
e.Appearance.BackColor = Color.FromArgb(226, 234,
253)
End If
End If
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
我正在使用DevExpress .i声明'DbNull'值应该是'Lightyellow'中的默认颜色。我希望在'DbNull'值中选择行或Cell来更改蓝色。我做错了什么? 我想要选择要更改颜色的细胞或行(也是空值)
答案 0 :(得分:0)
It doesn't make sense to iterate through the selected cells in the RowCellStyle event handler since this event is raised only for a single cell. Eventually, it will raise for all visible cells.
Thus, the following code will be enough to complete your task:
Private Sub GridView1_RowCellStyle(ByVal sender As Object, ByVal e As RowCellStyleEventArgs)
Dim view As GridView = TryCast(sender, GridView)
Dim isRowSelected As Boolean = view.IsRowSelected(e.RowHandle)
If IsDbNull(e.CellValue) AndAlso (Not isRowSelected) Then
e.Appearance.BackColor = Color.Yellow
End If
End Sub
Does it work for you?
答案 1 :(得分:0)
Dim state As GridRowCellState
state = DirectCast(e.Cell, GridCellInfo).State
If (state And GridRowCellState.Selected) = GridRowCellState.Selected Then
e.Appearance.BackColor = Color.FromArgb(226, 234, 253)
End If
此代码用于选择要更改外观颜色的单元格。 GridRowCellState包含网格控件的外观自定义事件的行单元格状态.Selected Cells is指定选择当前正在处理的行/单元格。 This is My Output