GridViewImageColumn Sorting not working

7 posts, 1 answers
  1. Yip Yew Kwong
    Yip Yew Kwong avatar
    14 posts
    Member since:
    May 2010

    Posted 30 Oct 2012 Link to this post

    We are using RadControls for Winforms Q1 2012. The sorting function is not working correctly for GridViewImageColumn. Please help. Thanks a lot!
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Nov 2012 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Yip Yew Kwong
    Yip Yew Kwong avatar
    14 posts
    Member since:
    May 2010

    Posted 04 Nov 2012 Link to this post

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

  5. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 07 Nov 2012 Link to this post

    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
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 07 Nov 2012 Link to this post

    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.
  7. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 07 Nov 2012 Link to this post

    Hello Stefan,

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

    Best Regards,
    Emanuel Varga
    Winforms MVP
  8. Yip Yew Kwong
    Yip Yew Kwong avatar
    14 posts
    Member since:
    May 2010

    Posted 07 Nov 2012 Link to this post

    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;
Back to Top
UI for WinForms is Visual Studio 2017 Ready