GridControl::SortCol

 

Description

Sort a column

Syntax

bool SortCol( int nCol, int nSortType )

Parameters

nCol
[input] 0-offset column index
nSortType
[input] sorting order defined in SortSettings

Return

true on successful or false on failure

Examples

The examples in this section will use an existing grid dialog resource DLL that gets installed with Origin C's Developer Kit. The DLL can be found in this zip file, under \Dialog Builder\GridDLG sub-folder.

#include <..\Originlab\DialogEx.h>
#include "GridDLGRes.h"// resource DLL header

class GridCtrlDLG : public ResizeDialog
{
public:
        GridCtrlDLG() : ResizeDialog(IDD_GRID_DLG, "GridDLG")
        {
        }

        int DoModal(HWND hParent = NULL)
        {
                InitMsgMap();
                int nRet = ResizeDialog::DoModal(hParent);
                return nRet;
        }

protected:
///----------------- Message Map ----------------
        EVENTS_BEGIN
                ON_INIT(OnInitDialog)
                ON_SIZE(OnDlgResize)
                ON_GETMINMAXINFO(OnMinMaxInfo)
                ON_OK(OnSort)
        EVENTS_END
///----------------------------------------------
        
        BOOL OnInitDialog()
        {
                ResizeDialog::OnInitDialog(0, "Grid Dialog");
                
                //initialize grid control
                m_GridCtrl.Init(IDC_GRID, *this);
                m_GridCtrl.SetupRowsCols( 1, 0, 11, 3 );
                
                m_GridCtrl.SetEditable(flexEDNone);
                m_GridCtrl.SetExplorerBar(flexExSort);
                
                m_GridCtrl.SetColheading(0, "Name");
                m_GridCtrl.SetColheading(1, "Age");
                m_GridCtrl.SetColheading(2, "Gender");
                
                vector<string> vsItems  = {"Kate", "Lose", "Jane", "Sophia", "Grace", "Tom", "James", "Sun", "Barb", "Alice",
                                                                        "12",    "12",    "12",    "13",            "13", "13",       "14", "14",       "14", "14", 
                                                                        "F",     "F",     "F",     "F",             "F",  "M",                "M",  "M",                "F",  "F"};
                m_GridCtrl.SetTableValue(vsItems, false);
                
                //move grid control to top left
                RECT rrList;    
                rrList.top = rrList.left = GetControlGap();
                m_GridCtrl.MoveWindow(rrList);
                
                GetItem(IDOK).Text = "Sort";
                
                SetInitReady();
                return TRUE;
        }     

        BOOL OnDlgResize(int nType, int cx, int cy)
        {
                if(!IsInitReady())
                        return TRUE;          
                
                uint nButtonIDs[] = {IDOK, 0};
                ArrangeMainItemAndControls(nButtonIDs, IDC_GRID, NULL, false);
                return TRUE;
                
        }
        
        BOOL OnSort()
        {
                m_GridCtrl.SortCol(1, flexSortNumericAscending);
                
                return FALSE;
        }
        
private:
        GridControl         m_GridCtrl;
};

bool OpenGridDLG()    
{
        GridCtrlDLG myDlg;
        myDlg.DoModal( GetWindow() );
        return true;
}

Remark

See Also

header to Included

GridControl.h