6 Answers, 1 is accepted
Thank you for writing.
By default the image column is sorted by the image size. If this comparison is not good for you, you can use the custom sorting functionality of RadGridView, and sort it as needed: http://www.telerik.com/help/winforms/gridview-sorting-custom-sorting.html.
I hope this helps.
All the best,
Stefan
the Telerik team
Hi Stefan,
Thanks for the response.
Sorting by size is good enough for us. But it is not working as expected. Please refer to my screen capture. After I clicked on the header of Lock colunm, it did not sort correctly. Whereas, if I clicked on "Security Event Name" and "Radius" colunms, it sorted correctly. BTW, we populated images in CellFormatting event as below:
void CellFormatting(object sender, CellFormattingEventArgs e)
{
var cellElement = e.CellElement;
try
{
dynamic obj = cellElement.RowInfo.DataBoundItem;
if (obj == null|| obj is RoutePlanObject) return;
DisplayToolTip(cellElement);
DisplayActivation(cellElement);
DisableRow(cellElement);
cellElement.Image = null;
switch (cellElement.ColumnInfo.Name)
{
case SpsCommon.RAD_GRID_VIEW_PUBLISH_SHARE_HEADING:
{
cellElement.Image = GetImage(obj.PublishShare == PublishShare.Share ? 2 : 3);
cellElement.ToolTipText = obj.PublishShare == PublishShare.Share ? "Shared" : "Published";
}
break;
case SpsCommon.RAD_GRID_VIEW_LOCK_HEADING:
if (obj.LOCK_FLAG == EditFlagType.Lock)
cellElement.Image = GetImage(0);
break;
case SpsCommon.RAD_GRID_VIEW_SCHEDULE_HEADING:
if (obj.Scheduled)
cellElement.Image = GetImage(4);
break;
case SpsCommon.RAD_GRID_VIEW_TAG_HEADING:
if (obj.Tag_Flag == "1")
cellElement.Image = GetImage(5);
break;
case SpsCommon.RAD_GRID_VIEW_TYPE_HEADING:
if (!String.IsNullOrEmpty(obj.GeoRectifiedContent))
{
cellElement.Image = GetImage(6);
cellElement.ToolTipText = "Geo-rectified image";
}
break;
default:
cellElement.Image = null;
break;
}
}
catch (Exception) { }
}
Because you are adding these images conditionally on the cell formatting event, the out of the box sorting will not work.
You should use custom sorting for this purpose, please take a look at this thread on how to get the current sort descriptors.
Hope this helps, if you have any other questions, please let me know.
Best Regards,
Emanuel Varga
Winforms MVP
I agree with Emanuel's statement and I am marking it as answer. (Welcome back Emanuel :))
Alternative solution will be to use GridViewImageColumn and populate the images for the rows, instead of doing so in the formatting event. This will allow you to use the default sorting functionality.
I hope this helps.
All the best,
Stefan
the Telerik team
Glad to be back :) and thank you for the warm welcome :).
Best Regards,
Emanuel Varga
Winforms MVP
Thanks both for the advice. I have managed to resolve the problem by adding an Image attribute in the binding data object. Then in the ViewFormatting event handler, I assign the cellElement.Image to the data object. It works perfectly.
case SpsCommon.RAD_GRID_VIEW_LOCK_HEADING:
if (obj.LOCK_FLAG == EditFlagType.Lock)
cellElement.Image = GetImage(0);
obj.Lock = cellElement.Image; //added line
break;