This is a migrated thread and some comments may be shown as answers.

Setting font to strikeout across entire row

1 Answer 507 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 22 Apr 2013, 07:24 PM
Hi, I am really struggling to cope with the object structure in GridView. I have a checkbox column which allows the user to tick to indicate that the row will be deleted when the whole grid is saved. I need this strikeout to occur immediately when the checkbox is ticked and thus have to use the RadGridView1_ValueChanged event. Trouble is that I just don't understand how I can access the font attributes of the cells on the current row and set the strikeout attribute. What is the difference between GridViewCellInfo and GridViewCellElement?

This is my VB code:

    Private Sub RadGridView1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles RadGridView1.ValueChanged
        If RadGridView1.CurrentColumn.HeaderText = "Del" Then
            If CBool(RadGridView1.CurrentCell.Value) = True Then
                Dim rowInfo As GridViewRowInfo = RadGridView1.CurrentRow
                For Each cellInfo As GridViewCellInfo In rowInfo.Cells
                    cellInfo.font()  'Doesn't work!
                Next
            End If
        End If
    End Sub

All the examples show using a CellElement object returned by an event but the ValueChanged event does not return this kind of object!

I am really struggling with the power of these grids in VB.Net having been used to a simpler life in VB6!

Thanks

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 26 Apr 2013, 04:55 AM
Hi Martin,

Thank you for writing.

I would strongly suggest that you get familiar with how RadGridView works and how it is build as there are some specifics in working with it. You can find more details in our online documentation.

On your question, you can do two things to achieve your goal. One is to use the CellFormatting event and change the font of the cells on a row that has the check box in the Del column checked. Here is the code:
Private Sub RadGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles RadGridView1.CellFormatting
    If Not (TypeOf e.Row Is GridViewDataRowInfo) Then
        Return
    End If
 
    If CBool(e.Row.Cells("Del").Value) Then
        e.CellElement.Font = New Font(e.CellElement.Font, FontStyle.Strikeout)
    Else
        e.CellElement.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local)
    End If
 
End Sub

Your second option is to use the RowPaint event and to draw a line across the whole row. Here is the code for that:
Private Sub RadGridView1_RowPaint(sender As Object, e As GridViewRowPaintEventArgs) Handles RadGridView1.RowPaint
    If TypeOf e.Row.RowInfo Is GridViewDataRowInfo AndAlso CBool(e.Row.RowInfo.Cells("Del").Value) Then
        e.Graphics.DrawLine(Pens.Black, e.Row.Location.X, e.Row.Location.Y + e.Row.Size.Height / 2.0F, e.Row.Location.X + e.Row.Size.Width, e.Row.Location.Y + e.Row.Size.Height / 2.0F)
    End If
End Sub

Finally, if you want to see the changes in the UI after clicking the check box you can subscribe to the ValueChanged event and call the grid EndEdit method. This is needed because of the grid editing mechanism.
Private Sub RadGridView1_ValueChanged(sender As Object, e As EventArgs) Handles RadGridView1.ValueChanged
    If Me.RadGridView1.CurrentColumn.Name = "Del" Then
        Me.RadGridView1.EndEdit()
    End If
End Sub

I hope this will be useful. Should you have further questions, I would be glad to help.

Greetings,
Ivan Petrov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or