2017-10-12 105 views
0
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 

This is my Output Screen Devexpress xtragridXtraGrid中细胞和行选择使用的DevExpress的WinForms Vb.net

我使用的DevExpress。我声明“的DBNull的价值应该是“Lightyellow'.After默认颜色我想成为选择行或“DbNull”值中的单元格更改蓝色。我做错了什么? 我想要选择单元格或行来改变颜色(即null值)

+0

什么应该变成蓝色?整排,还是那个细胞? – greenTree

+0

被选中的行或单元格将被更改为蓝色(即Null值也是) –

回答

0

在RowCellStyle事件处理程序中迭代所选单元没有意义,因为此事件仅针对单细胞。最终,它会提高所有可见的单元格。

因此,下面的代码将足以完成你的任务:

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 

它是否适合你?

+0

第i个选定的特定HireDate列单元格,但几乎为null的单元格值也会更改黄色。但我只需要选择空值更改为蓝色颜色。 –

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包含网格控件的外观定制事件的行单元格状态。选定单元格指定选择当前正在处理的行/单元格。 This is My Output

+4

仅提供代码解答。你能否添加详细的解释你的答案? – DiskJunky

+1

请复习[我如何写出一个好答案](https://stackoverflow.com/help/how-to-answer)。不接受代码的答案是不鼓励的,因为他们没有解释他们如何解决问题中的问题。你应该更新你的答案,以解释这是什么以及如何解决问题。 – FluffyKitten

相关问题