2.2.6.17.52 GridControl::HideCol


Description

Hides or displays the given column.

Syntax

bool HideCol( int nCol = -1, bool bHide = true )

Parameters

nCol
[input] column to hide or diaplay, 0-offset column index. If nCol = -1, it will hide or display all columns
bHide
[input] true to hide the given column and false to display

Return

false if nCol is invalid, otherwise true

Examples

This section describes how to open a dialog with grid control in Origin C. You can show/hide grid column by right click at the grid.

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

#define STR_COL_NAMES		"Name|Age|Gender"

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( 3, 0, 5, 1 );
		m_GridCtrl.SetColHeader(STR_COL_NAMES);
		
		//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)
		{
			vector<string> vsNames;
			int nSize = str_separate(STR_COL_NAMES, "|", vsNames);
			
			vector<byte> vbHide;
			m_GridCtrl.GetHiddenCols(vbHide);
			ASSERT(vbHide.GetSize() == nSize);
			
			Menu menuCols;
			int nCmd;
			for(int nCol = 0; nCol < nSize; nCol++)
			{
				nCmd = nCol+1;
				menuCols.Add(vsNames[nCol], nCmd, vbHide[nCol]? MF_UNCHECKED : MF_CHECKED);
			}
			menuCols.Add(NULL, 0, MF_SEPARATOR);
			menuCols.Add("Show All", 100, MF_STRING);
			
			nCmd = 0;
			menuCols.TrackPopupMenu(0, nx, ny, GetSafeHwnd(), &nCmd);
			if(nCmd > 0)
			{
				if(nCmd <= nSize)
				{
					nCol = nCmd-1;
					m_GridCtrl.HideCol(nCol, !vbHide[nCol]);
				}
				else
				{
					vbHide = false;
					m_GridCtrl.SetHiddenCols(vbHide);
				}
			}
		}
		return TRUE;
	}
	
private:
	GridControl         m_GridCtrl;
};

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

Remark

See Also

GridControl::SetHiddenCols
GridControl::GetHiddenCols

Header to Included

GridControl.h