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

Adding an image to the GridRowHeaderCellElement

3 Answers 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
OverCoded
Top achievements
Rank 2
OverCoded asked on 25 May 2010, 02:37 PM
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.

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 27 May 2010, 04:26 PM
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.
0
george mcnitt
Top achievements
Rank 1
answered on 29 Nov 2010, 06:22 PM

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
       


0
Martin Vasilev
Telerik team
answered on 03 Dec 2010, 09:38 AM
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.
Tags
GridView
Asked by
OverCoded
Top achievements
Rank 2
Answers by
Martin Vasilev
Telerik team
george mcnitt
Top achievements
Rank 1
Share this question
or