Adding an image to the GridRowHeaderCellElement

4 posts, 0 answers
  1. OverCoded
    OverCoded avatar
    34 posts
    Member since:
    Mar 2010

    Posted 25 May 2010 Link to this post

    I have a radgrid that I want to add an image to the GridRowHeaderCellElement ImagePrimative dynamically. I don't want to ad the image unless a certain condition is met. I don't think conditional formatting will work because the GridRowHeaderCellElement does not contain any data. The condition will be calculated on a hidden cell in the row. I want the image in the GridRowHeaderCell to show graphicly that this record contains certain other data, sort of like a flag.
    How do I access the GridRowHeaderCellElement Imageprimative property to assign an image while looping through the rows? I am using hierarchial data so the expander cell is occupied. I need access to the header or Indent cell properties for each row.
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 27 May 2010 Link to this post

    Hi Mark Coe,

    Thank you for contacting us.

    You should use ViewCellFormatting event to access GridRowHeaderCellElement and set a picture to it. Please, consider the following code snippet as an example of how to do that:
    void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement is GridRowHeaderCellElement)
        {
            object value = e.CellElement.RowInfo.Cells["myCondition"].Value;
            if (value != null && (int)value == 1)
            {
                Assembly myAssembly = Assembly.GetExecutingAssembly();
                Stream myStream = myAssembly.GetManifestResourceStream("ProjectNamespace.Images.myImage.gif");
                Bitmap bmp = new Bitmap(myStream);
                e.CellElement.Image = bmp;
            }
        }
    }

    I hope this helps. Let me know if you have any additional questions.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. george mcnitt
    george mcnitt avatar
    14 posts
    Member since:
    May 2010

    Posted 29 Nov 2010 Link to this post

    Martin I was using your code example recently and it was working just fine.

    Recently I updated the radgrid to the current verison and have noticed that the images in the rowheader no longer display.

    The call to (e.cellelement.image = image)  is executing in the ViewCellFormatting event as it should, the image just never shows up.

    Has something changed recently that would cause the image to stop displaying?

    Below is my current code that was working but is not now.

               If TypeOf e.CellElement Is GridRowHeaderCellElement Then
                   Dim notes As Object = e.CellElement.RowInfo.Cells("notes").Value
                   Dim note_image As Image = ImageList3.Images.Item(29)
                   If ((Not Convert.IsDBNull(notes)) AndAlso notes IsNot Nothing AndAlso notes.ToString() <> String.Empty) Then
                       e.CellElement.Image = note_image
                   End If
               End If
           


  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 03 Dec 2010 Link to this post

    Hello george mcnitt,

    Thank you for writing.

    Actually, we have recently found an issue with the ViewCellFormatting event, which prevents you from setting a custom image to GridRowHeaderCellElement in the way described in my initial answer. We have already addressed this and the fix will be available in the Service Pack 1 release. For the time being, you can work-around this by using CellElement's BackgroundImage instead of the Image property.

    Let me know if you have any additional questions.

    Regards,
    Martin Vasilev
    the Telerik team
    Get started with RadControls for WinForms with numerous videos and detailed documentation.
Back to Top