2017-10-12 103 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

相關問題