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

RadImageItem will not center in GridCellElement

1 Answer 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
dootndo2
Top achievements
Rank 1
dootndo2 asked on 14 Nov 2007, 09:58 PM
I used the property builder tool and added a checkboxcolumn to my radgridview.  I want to have an picturebox in the column that will put a different image based upon some boolean value.

I have everything working, but I cannot get the control to be centered in the column.  I am adding the RadImageItem as such:

        If TypeOf e.CellElement.ColumnInfo Is GridViewDataColumn AndAlso DirectCast(e.CellElement.ColumnInfo, GridViewDataColumn).DataField = "HasComments" Then 
            If Not (TypeOf e.CellElement.RowElement Is GridHeaderRowElement) Then 
                'exclude Header element in the data column   
                If e.CellElement.Children.Count > 0 Then 
                    If e.CellElement.Children(0).GetType() Is GetType(Telerik.WinControls.UI.RadCheckBoxEditor) Then 
                        ' remove the checkbox  
                        e.CellElement.Children.RemoveAt(0)  
                      
                        Dim pieceid As Integer = CType(e.CellElement.RowElement.RowInfo.Cells("PieceId").Value, Integer)  
                        Dim hasComments As Boolean = ' load has comments  
 
                        Dim img As RadImageItem = New RadImageItem()  
 
                        If hasComments Then 
                            img.Image = My.Resources.Resources.green  
                        Else 
                            img.Image = My.Resources.Resources.red  
                        End If 
 
                        e.CellElement.Children.Add(img)  
                        e.CellElement.Children(0).Alignment = ContentAlignment.MiddleCenter  
                        e.CellElement.Alignment = ContentAlignment.MiddleCenter  
 
                    End If 
                End If 
            End If 
        End If 

I'm sure that there is an easy way to do this, but I am not able to locate it.  The Alignment Properties do not seem to adjust this.

Thanks as always.

Dennis

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Nov 2007, 12:22 PM
Hi dootndo2,

Thank you for writing.

This can be done by using the Image property of GridCheckBoxCellElement. The best place to assign an image to a cell is the CellFormatting event. Refer to the sample below:

Private  Sub radGridView1_CellFormatting(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) 
    e.CellElement.PaintTextFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None 
    If TypeOf e.CellElement Is GridCheckBoxCellElement Then 
        If e.CellElement.Children.Count > 0 Then 
            e.CellElement.Children.RemoveAt(0) 
            e.CellElement.Image = Resources.vgrip 
        End If 
    End If 
End Sub 


In case you have further questions, we will be glad to help you.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
dootndo2
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or