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

GridViewImageColumn Sorting not working

6 Answers 199 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yip Yew Kwong
Top achievements
Rank 1
Yip Yew Kwong asked on 31 Oct 2012, 02:11 AM
We are using RadControls for Winforms Q1 2012. The sorting function is not working correctly for GridViewImageColumn. Please help. Thanks a lot!

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Nov 2012, 10:53 AM
Hello Yip,

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
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Yip Yew Kwong
Top achievements
Rank 1
answered on 05 Nov 2012, 02:19 AM

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) { }
        }

0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 07 Nov 2012, 11:43 AM
Hello, 

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
0
Stefan
Telerik team
answered on 07 Nov 2012, 12:22 PM
Hi,

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
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Nov 2012, 12:26 PM
Hello Stefan,

Glad to be back :) and thank you for the warm welcome :).

Best Regards,
Emanuel Varga
Winforms MVP
0
Yip Yew Kwong
Top achievements
Rank 1
answered on 07 Nov 2012, 11:57 PM
Hi Stefen and  Emanuel, 

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;
Tags
GridView
Asked by
Yip Yew Kwong
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Yip Yew Kwong
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or