Search This Blog

Friday, November 30, 2012

How to change colums color to RadGridView (VB.NET)

Telerik > RadGridView > Cell Formatting

CellFormatting event is used to add formatting to grid cells

Because of UI virtualization in RadGridView, cell elements are created only for currently visible cells.
To prevent applying the formatting to other columns' cell elements all customization should be reset for the rest of the cell elements.
          
Example:
Change Forecolor in CellFormating Events
 

Imports Telerik.WinControls.UI
Imports Telerik.WinControls

Private Sub grd_CellFormatting(sender As System.Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles grd.CellFormatting
 
 If e.CellElement.ColumnInfo.Name = "total" Then
  e.CellElement.ForeColor = Color.Blue
 Else
  e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
 End If

End Sub