Click here to Skip to main content
15,892,298 members
Articles / Desktop Programming / MFC

The Ultimate Grid Home Page

,
Rate me:
Please Sign up or sign in to vote.
5.00/5 (122 votes)
14 Sep 2013CPOL10 min read 4.6M   81.9K   418  
The Ultimate Grid is now Open Source
/***************************************************
****************************************************
Skeleton Class for a Derived MyCug 
****************************************************
****************************************************/

#include "stdafx.h"
#include "resource.h"
#include "MyCug.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(MyCug,CUGCtrl)
	//{{AFX_MSG_MAP(MyCug)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/***************************************************
****************************************************/
MyCug::MyCug()
{
}
/***************************************************
****************************************************/
MyCug::~MyCug()
{
	UGXPThemes::CleanUp();
}

/***************************************************
OnSetup
	This function is called just after the grid window 
	is created or attached to a dialog item.
	It can be used to initially setup the grid
****************************************************/
void MyCug::OnSetup(){

	UseDefaultStateStorage(FALSE);
	
	// initialize local variables
	int rows = 30,
		cols = 15,
		i,j;
	CUGCell	cell;

	// setup rows and columns
	SetNumberRows(rows);
	SetNumberCols(cols);

	// limit number of decimal points in the cell (0,0) to 0 (none)
	GetCell(0,1,&cell);
	cell.SetNumberDecimals(0);

	// fill-in cells with data
	for (i = 0; i < cols; i++)
		for (j = 0; j < rows; j++) {
			cell.SetNumber(rand()%1000);
			SetCell(i,j,&cell);
		}
	// setup titles for top and side headings
	for (i=0;i < cols;i++){
		cell.SetNumber (i+1);
		SetCell (i,-1,&cell);
	}
	for (j=0;j < rows;j++){
		cell.SetNumber (j+1);
		SetCell (-1,j,&cell);
	}
	// put text in first row ..
//	GetCell(0,0,&cell);
//	cell.SetText("Right click on the grid to invoke menu...");
//	SetCell(0,0,&cell);

	// create pop-up menu
	EnableMenu(TRUE);
	AddMenuItem(1001,"Insert Row");		// 'Insert Row' menu item
	AddMenuItem(1002,"Delete Row");		// 'Delete Row' menu item
	AddMenuItem(1003,"Insert Column");	// 'Insert Column' menu item
	AddMenuItem(1004,"Delete Column");	// 'Delete Column' menu item
}

/***************************************************
sections - UG_TOPHEADING, UG_SIDEHEADING,UG_GRID
			UG_HSCROLL  UG_VSCROLL  UG_CORNERBUTTON
****************************************************/
void MyCug::OnMenuCommand(int col,long row,int section,int item){
	// if right mouse click outside grid area, exit
	if (section != UG_GRID)
		return;
	
	switch (item) {
	case 1001:		// "Insert Row"
		InsertRow(row);	
		break;
	case 1002:		// "Delete Row"
		DeleteRow(row);
		break;
	case 1003:		// "Insert Column"
		InsertCol(col);
		break;
	case 1004:		// "Delete Column"
		DeleteCol(col);
		break;
	}
	RedrawAll();
}
/***************************************************
return UG_SUCCESS to allow the menu to appear
return 1 to not allow the menu to appear
****************************************************/
int MyCug::OnMenuStart(int col,long row,int section){
	if (section != UG_GRID)
		return FALSE;
	return TRUE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions