GridControl::GetColAlignment

 

Contents

Description

Gets the alignment of the given column

Syntax

int GetColAlignment( long Col )

Parameters

Col
[input] 0-offset column index

Return

alignment setting defined in AlignmentSettings

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.

/*flexAlignLeftTop = 0,
    flexAlignLeftCenter = 1,
    flexAlignLeftBottom = 2,
    flexAlignCenterTop = 3,
    flexAlignCenterCenter = 4,
    flexAlignCenterBottom = 5,
    flexAlignRightTop = 6,
    flexAlignRightCenter = 7,
    flexAlignRightBottom = 8,
    flexAlignGeneral = 9
*/
#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_CONTEXTMENU(OnShowMenu)
        EVENTS_END
///----------------------------------------------
        
        BOOL OnInitDialog()
        {
                ResizeDialog::OnInitDialog(0, "Grid Dialog");
                
                //initialize grid control
                m_GridCtrl.Init(IDC_GRID, *this);
                m_GridCtrl.SetupRowsCols( 1,1, 5, 2 );
                
                vector<string> vsItems = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
                vector<string> vsItems2 = {"week1", "week2", "week3"};
                m_GridCtrl.CheckExpandRows( vsItems.GetSize()-1);
                m_GridCtrl.SetFixedRowValues(0,vsItems, 0,true);
                m_GridCtrl.SetCells(vsItems, 0);
                m_GridCtrl.SetCells(vsItems, 1);
                
                //move grid control to top left
                RECT rrList;    
                rrList.top = rrList.left = GetControlGap();
                m_GridCtrl.MoveWindow(rrList);
                
                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 OnShowMenu(UINT nResIDCtrl, int nx, int ny)
        {
                if(IDC_GRID == nResIDCtrl)
                {
                        int nRow, nCol;
                        m_GridCtrl.GetMouseCell(nRow, nCol);
                        UINT nFlags = m_GridCtrl.IsInGrid(nRow, nCol) && (nCol-m_GridCtrl.GetColOffset()>=0) && (nRow-m_GridCtrl.GetRowOffset()>=0);
                        UINT nFlag = nCol!=-1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED;

                        m_GridCtrl.SetIsSelected(nRow, true);
                        
                        Menu menuRows;
                        menuRows.Add("LeftTop", 1, nFlag);
                        menuRows.Add("CenterCenter", 2, nFlag);
                        menuRows.Add("RightBottom", 3,  nFlag);
                
                        
                        int nCmd = 0;
                        int nAlignment;
                        menuRows.TrackPopupMenu(0, nx, ny, GetSafeHwnd(), &nCmd);
                        switch(nCmd)
                        {
                        case 1:
                                nAlignment=flexAlignLeftTop;
                                break;
                                
                        case 2:
                                nAlignment=flexAlignCenterCenter;
                                break;
                                
                        case 3:
                                nAlignment=flexAlignRightBottom;
                                break;                             
                        }
                        if(nFlags)
                                        m_GridCtrl.SetColAlignment(nCol-m_GridCtrl.GetColOffset(),nAlignment,false);
                                        
                                else
                                        {
                                        out_int("previous fixed col alignment is ",m_GridCtrl.GetFixedAlignment(nCol));
                                        m_GridCtrl.SetFixedColAlignment(nCol-m_GridCtrl.GetColOffset(),nAlignment,false);
                                        out_int("now fixed col alignment is ",m_GridCtrl.GetFixedAlignment(nCol));
                                }
                                
                }
                
                return TRUE;
        }
        
private:
        GridControl         m_GridCtrl;
};

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

Remark

See Also

GridControl::SetColAlignment

header to Included

GridControl.h