Click here to Skip to main content
15,895,084 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
// DAO sortingView.cpp : implementation of the CDAOsortingView class
//

#include "stdafx.h"
#include "DAO sorting.h"

#include "DAO sortingDoc.h"
#include "DAO sortingView.h"
#include "OpenDatabaseDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDAOsortingView

IMPLEMENT_DYNCREATE(CDAOsortingView, CView)

BEGIN_MESSAGE_MAP(CDAOsortingView, CView)
	//{{AFX_MSG_MAP(CDAOsortingView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDAOsortingView construction/destruction

CDAOsortingView::CDAOsortingView()
{
	// TODO: add construction code here

}

CDAOsortingView::~CDAOsortingView()
{
}

BOOL CDAOsortingView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDAOsortingView drawing

void CDAOsortingView::OnDraw(CDC* pDC)
{
	CDAOsortingDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	if ( pDC->IsPrinting())
	{
		m_grid.PrintPage(pDC, m_printPage);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDAOsortingView printing

BOOL CDAOsortingView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDAOsortingView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// make sure that all of the rows in the grid are showing
	m_grid.SetNumberRows( m_data.GetNumRowsComplete());

	pInfo->SetMaxPage(m_grid.PrintInit(pDC,pInfo->m_pPD,0,0,m_grid.GetNumberCols()-1,m_grid.GetNumberRows()-1));
}

void CDAOsortingView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDAOsortingView diagnostics

#ifdef _DEBUG
void CDAOsortingView::AssertValid() const
{
	CView::AssertValid();
}

void CDAOsortingView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDAOsortingDoc* CDAOsortingView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDAOsortingDoc)));
	return (CDAOsortingDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDAOsortingView message handlers

int CDAOsortingView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	m_grid.CreateGrid( WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, 23423 );
	
	// configure DAO datasource before oppenig
	m_data.SetOption( UGDAO_OPT_ALLOWEDITS, 1, 0 );
	m_data.SetOption( UGDAO_OPT_GHOSTROWMODE, 1, 0 );

	// get sql and location of the selected database
	COpenDatabaseDlg openDlg;
	if ( openDlg.DoModal() == IDOK )
	{	
		if ( openDlg.m_openStyle == 0 )
		{	// open datasource with SQL, and looking for records that do not exist
			// therefore returning empty recordset
			m_data.OpenSQL( openDlg.GetFileName(), openDlg.GetSQL());
		}
		else
		{	// open datasource with table name
			m_data.Open( openDlg.GetFileName(), openDlg.m_tableName );
		}
		// add default data source to the grid
		m_dataIndex = m_grid.AddDataSource( &m_data );
		m_grid.SetDefDataSource( m_dataIndex );
		// set grid using new datasource
		m_grid.SetGridUsingDataSource( m_dataIndex );
		// m_grid.SetNumberRows( m_data.GetNumRowsComplete());
		// do best fit
		// m_grid.BestFit( 0, m_data.GetNumCols() -1 , m_grid.GetNumberRows() -1, 0 );
	}
	else
		// action canceled by user
		return 0;

	m_grid.SetMultiSelectMode( TRUE );

	return 0;
}

void CDAOsortingView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	m_grid.MoveWindow( 0, 0, cx, cy );
}

BOOL CDAOsortingView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return FALSE;
	//return CView::OnEraseBkgnd(pDC);
}

void CDAOsortingView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	m_printPage = pInfo->m_nCurPage;

	CView::OnPrint(pDC, pInfo);
}

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