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

Cell format

2 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe Bohen
Top achievements
Rank 1
Joe Bohen asked on 28 Jun 2009, 08:36 AM

I have an image cell where the image is added conditionally using CellFormatting:

Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting

        Try

 

            If e.CellElement.ColumnIndex = 1 Then

                If CType(e.CellElement.RowInfo.Cells("type").Value = 0, Decimal) Then

                    e.CellElement.Image = Me.ImageList1.Images(0)

                ElseIf CType(e.CellElement.RowInfo.Cells("type").Value = 1, Decimal) Then

                    e.CellElement.Image = Me.ImageList1.Images(1)

                ElseIf CType(e.CellElement.RowInfo.Cells("type").Value = 2, Decimal) Then

                    e.CellElement.Image = Me.ImageList1.Images(2)

                ElseIf CType(e.CellElement.RowInfo.Cells("type").Value = 3, Decimal) Then

                    e.CellElement.Image = Me.ImageList1.Images(3)

                Else

                    e.CellElement.Image = Me.ImageList1.Images(3)

                End If

            End If

            e.CellElement.DrawFill = True

            If Not IsDBNull(e.CellElement.RowInfo.Cells("Status").Value) Then

                e.CellElement.DrawFill = True

                Select Case (e.CellElement.RowInfo.Cells("Status").Value)

                    Case 23

                        e.CellElement.BackColor = Color.Pink

                    Case 24

                        e.CellElement.BackColor = Color.Chartreuse

                    Case 25

                        e.CellElement.BackColor = Color.Yellow

                    Case 26

                        e.CellElement.BackColor = Color.SkyBlue

                    Case 27

                        e.CellElement.BackColor = Color.LightCyan

                    Case 28

                        e.CellElement.BackColor = Color.Crimson

                    Case 29

                        e.CellElement.BackColor = Color.Blue

                    Case 30

                        e.CellElement.BackColor = Color.Red

                    Case Else

                End Select

            Else

                e.CellElement.BackColor = Color.WhiteSmoke

            End If

 

        Catch ex As Exception

            MsgBox(Err.Description)

        End Try

    End Sub

This colours the whole row I only want the background behind the image to have the colour applied how do I do this?

Regards
Joe

2 Answers, 1 is accepted

Sort by
0
Accepted
Victor
Telerik team
answered on 02 Jul 2009, 07:26 AM
Hello Joe Bohen,

CellFormatting event fires for each and every data cell in RadGridView. This is why the code you have written colors whole rows.

To color only the background of the image cell you need to move the last if statement and its body inside the previous if statement so that e.CellElement.DrawFill will be set only if e.CellElement.ColumnIndex is 1.

Kind regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Joe Bohen
Top achievements
Rank 1
answered on 04 Jul 2009, 07:25 AM
Hi Victor

Thanks for the reply I can see the login now!

Regards
Joe
Tags
GridView
Asked by
Joe Bohen
Top achievements
Rank 1
Answers by
Victor
Telerik team
Joe Bohen
Top achievements
Rank 1
Share this question
or