Wednesday, July 22, 2015

Change Cell Color Based By Cell Value Using Devexpress Xtragrid on VB.NET

In some case when we load data from database to grid, we want to change backcolor/forecolor on some cell depends by its value. like this pic below:

Change cell backcolor/forecolor based by cell value
The point is to get the user attention in some value that needs to be look, in this case I use xtragrid from devexpress component, So here its code:

Imports DevExpress.XtraGrid.Views.Grid 
'-----
Dim View As GridView = sender  
     If e.Column.FieldName = "slsh_Keluar" Then  
       Dim _sklrVal As Integer = View.GetRowCellValue(e.RowHandle, View.Columns("slsh_Keluar"))  
       If _sklrVal <> 0 Then  
         e.Appearance.BackColor = Color.Red  
         e.Appearance.ForeColor = Color.Yellow  
         'e.Appearance.BackColor2 = Color.Yellow  
       End If  
     End If  
     If e.Column.FieldName = "slsh_masuk" Then  
       Dim _smskVal As Integer = View.GetRowCellValue(e.RowHandle, View.Columns("slsh_masuk"))  
       If _smskVal <> 0 Then  
         e.Appearance.BackColor = Color.Red  
         e.Appearance.ForeColor = Color.Yellow  
       End If  
     End If  

Good Luck..



1 comment: