RadImageItem will not center in GridCellElement

2 posts, 0 answers
  1. dootndo2
    dootndo2 avatar
    10 posts
    Member since:
    Dec 2006

    Posted 14 Nov 2007 Link to this post

    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:

    1         If TypeOf e.CellElement.ColumnInfo Is GridViewDataColumn AndAlso DirectCast(e.CellElement.ColumnInfo, GridViewDataColumn).DataField = "HasComments" Then 
    2             If Not (TypeOf e.CellElement.RowElement Is GridHeaderRowElement) Then 
    3                 'exclude Header element in the data column   
    4                 If e.CellElement.Children.Count > 0 Then 
    5                     If e.CellElement.Children(0).GetType() Is GetType(Telerik.WinControls.UI.RadCheckBoxEditor) Then 
    6                         ' remove the checkbox  
    7                         e.CellElement.Children.RemoveAt(0)  
    8                       
    9                         Dim pieceid As Integer = CType(e.CellElement.RowElement.RowInfo.Cells("PieceId").Value, Integer)  
    10                         Dim hasComments As Boolean = ' load has comments  
    11  
    12                         Dim img As RadImageItem = New RadImageItem()  
    13  
    14                         If hasComments Then 
    15                             img.Image = My.Resources.Resources.green  
    16                         Else 
    17                             img.Image = My.Resources.Resources.red  
    18                         End If 
    19  
    20                         e.CellElement.Children.Add(img)  
    21                         e.CellElement.Children(0).Alignment = ContentAlignment.MiddleCenter  
    22                         e.CellElement.Alignment = ContentAlignment.MiddleCenter  
    23  
    24                     End If 
    25                 End If 
    26             End If 
    27         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
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 15 Nov 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top