Telerik RadGridView – Updating DataTemplate For GridViewImageColumn
This is a quick tip for people doing Silverlight development with the Telerik control set. Particuarlly if you are using the RadGridView.
If you are updating a GridViewImageColumn, a lot of the examples out there say to set the GridViewCellBase.ContentTemplate by indexing on the cell collection. Don’t do this. It appears to arbitrarly updated other columns. Even when they are the wrong column type which is random. So if you are doing this:
- GridViewRowItem xGridViewRow = RadGridView.CurrentCell.ParentRow;
- GridViewCellBase cell = xGridViewRow.Cells[1];
- cell.ContentTemplate = "Selecting Some DataTemplate";
Iterate the cell collection instead and test whatever; header, type, really whatever you want. It’s more consistent. For example, to test the column type:
- GridViewRowItem xGridViewRow = RadGridView.CurrentCell.ParentRow;
- foreach (GridViewCellBase x in xGridViewRow.Cells.Where(x => x.Column is GridViewImageColumn))
- {
- x.ContentTemplate = "Selecting Some DataTemplate";
- }
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic