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

Default cell painting. Is there recommendation?

1 Answer 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Czeshirecat asked on 11 Jul 2017, 12:42 PM

I've got a grid cell that is painted with (or contains) an array of 0 - 4 icons which represent the methods in which a customer was contacted during a certain period.

At first I wanted to create an image and assign it to the cell's image property (seemed the easiest option) but it gave me 2 problems.

1) The cell insisted on displaying the image in the centre of the cell even though I'd told the image content to align left.

2) I couldn't think of a safe method to make sure the images are disposed of when no longer in use eg after paging/filtering/sorting etc.

So I thought that I'd use the cell paint event and paint an image to e.cell.graphics as I'd not need to do any memory management.

But there's little info in your help files about how to paint all the default parts of a cell. ie if one wanted to paint a default cell, but draw an image onto it so that selected colours, text fonts, back colour, theming etc etc etc looked the same on the cell. (Multi themed app)

In the microsoft grid view CellPaint event, there's a flag that the dev sets to say that painting has been done, to prevent infinite recursing. I've noticed that flag isn't in your grid view. I wondered how that effected the cell paint if you only wanted to paint a single column of the grid for example.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Jul 2017, 08:32 AM
Hi Claire,

Thank you for writing.

1, 2 You can use GridViewImageColumn. This way you can easily set the alignment and you will have reference to each image (which will allow you to dispose of the images if needed):
GridViewImageColumn imageColumn = new GridViewImageColumn();
imageColumn.Name = "ImageColumn";
imageColumn.FieldName = "Photo";
imageColumn.HeaderText = "Picture";
imageColumn.ImageLayout = ImageLayout.None;
imageColumn.ImageAlignment = ContentAlignment.MiddleLeft;
radGridView1.Columns.Add(imageColumn);
 
var img = Image.FromFile(@"C:\img\delete.png");
  
for (int i = 0; i < 10; i++)
{
    radGridView1.Rows.Add(img);
}

Please note that manually painting in the cell does not break the existing functionality. It allows you to paint in the cell rectangle, and in this case, you can paint the image inside the cell so it does not cover the border and the entire background. There is no need to set any flags as well.

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or