Sorting of msflexgrid control in VC++

I want to sort data that is being displayed in my msflexgrid control. All data of a column needs to be sorted on the selection of the column header. Just like we can sort the items in our inbox in outlook by clicking on the tab headings "From", "Date", "Subject", etc.

This is a very simple task in VB. But I am unable to find the method to implement it using VC++. Can somebody please help



Answer this question

Sorting of msflexgrid control in VC++

  • Teymur Hajiyev

    Hello Sharat,

    You can get help from the document "MSHFLX98.CHM" which may be there in your machine. You can give a search in your machine with the filename.

    If this doc is not available in your machine, feel free to ask me at jahfer@gmail.com

    Regards,
    Jahfer V P.

  • Shula

    Hi

    Jahfer, thanks for that, but that does not address my problem. I have already gone through the Windows help file for the Flexgrid. And I have gone through the properties, methods and events for this control.

    These do not help me in my objective. I want to sort the items in the grid based on the column header I select. As, I said in my earlier mail, to look at what I want to do, you just observe how the inbox of your Outlook works. You click on the "Subject " header and all the mails are sorted in alphabetical order based on the Subject of the mail. On clicking on "Subject" again, the order of sorting toggles between ascending to descending. The same can be performed with "Date", "Importance", etc.

    I have a function to sort the contents of the grid. Let me give you that code snippet. It is as follows:

     int col_no;
     int sorting_order;
     m_Grid.SetCol(col_no);
     m_Grid.SetSort(sorting_order);

    The SetCol function sets the column for which the sorting needs to be done. The SetSort function sorts the Grid by this column in an ascending or descending order (based on the parameter sorting_order).

    My problem is that I need to get the col_no when the user clicks on any of the column headers. I am unable to do that since the column headers are set in the first row of the Grid which I have set as a fixed row. Even if I change this row from fixed to normal, all the rows have SetSelection set to rowwise selection. This means that if I select any cell, the entire row in which that cell lies would get selected. Hence, I would not be able to extract the column number on which the user had clicked.

    If anybody can just tell me how to extract the column number on which a click event has taken palce when the SetSelection is set to row-wise selection, I will be able to solve the rest of the problems pretty easily.

    Looking forward to helpful responses.

    Thanks


  • Karsinogeeni

    Thank you Ronald. That was exactly what I needed. I used the GetMouseCol() method and now am able to accomplish the task. Thanks a lot for your help, guys!!
    Big Smile



  • Fidencio Monroy

    Hi,

    In a handler for the MouseUp event, check the MouseCol property (and the MouseRow one if you only want a click on the top row to start the sort).

    Ronald Laeremans
    Visual C++ team

  • Sorting of msflexgrid control in VC++