Telerik Winforms RadGridView CellFormatting event

The value of this article is not so much the content, but its place on the DD menu. Take a second and click on the line above that invites you to the menu page and familiarize yourself with where this article is on the menu. If you use Telerik (Progressive) products, you'll need this soon enough ... and the benefit is being able to find it when you need it. 

So...

This article will show some code examples for the Telerik Winforms CellFormatting event

 

Change the cell color

Private Sub RadGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles RadGridView1.CellFormatting
 
    Select Case e.CellElement.ColumnInfo.HeaderText
        Case "Receipt Qty"
            Select Case e.CellElement.RowInfo.Cells("QtyMismatch1").Value
                Case 1
                    e.CellElement.DrawFill = True
                    e.CellElement.ForeColor = Color.Red
                    e.CellElement.NumberOfColors = 1
                Case Else
                    e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
                    e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
                    e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local)
            End Select
    End Select
End Sub

Similar to the above

e.CellElement.DrawFill = True
e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
e.CellElement.ForeColor = Color.Maroon

Make a cell Read Only

If e.CellElement.ColumnIndex = 0 Then
    If Not Me.DragAndDropGrid1.CurrentCell Is Nothing Then
        If Me.DragAndDropGrid1.CurrentRow.Cells("TruckPO").Value > "" Then
            e.CellElement.ColumnInfo.[ReadOnly] = True
        Else
            e.CellElement.ColumnInfo.[ReadOnly] = False
        End If
    End If
End If

Disable/Enable a cell

If e.CellElement.ColumnInfo.Name = "cmdFileName" Then
    If e.CellElement.Value = "" Then
        e.CellElement.Enabled = False
    Else
        e.CellElement.Enabled = True
    End If
End If

Another way to hide a cell

Select Case e.CellElement.ColumnInfo.HeaderText.ToUpper
    Case "DELETE"
        If Not e.CellElement.RowInfo.Cells("unitprce").Value Is System.DBNull.Value Then
            e.CellElement.Visibility = ElementVisibility.Collapsed
        End If
End Select

 

 

 

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences