grid.cpp

来自「一个关于MSFlexGrid使用的例子,能够进行表格的编辑等操作」· C++ 代码 · 共 152 行

CPP
152
字号
// m_Grid->cpp: implementation of the CGrid class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FlexGrid.h"
#include "grid.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGrid ::CGrid()
{

	
	
}


CGrid ::~CGrid()
{

}


BOOL CGrid ::GoUp()
 
{
	
	TransferValue(TRUE);
	if (GetRow () > 1 ) {
		int CurrentRow = GetRow();
		CurrentRow --;
		SetRow (CurrentRow );
		TransferValue (FALSE);
		if (! GetRowIsVisible (CurrentRow)) 
            SetTopRow (CurrentRow  );

	}
	return TRUE;

	
}


BOOL CGrid ::GoDown()
{
	
	TransferValue(TRUE);
	if ( GetRow () < GetRows () -1) {
		int CurrentRow = GetRow();
		CurrentRow ++;
		SetRow ( CurrentRow);
		TransferValue (FALSE);
		if (! GetRowIsVisible (CurrentRow)) 
            SetTopRow (CurrentRow );
	}


	return TRUE;

}


BOOL CGrid ::GoLeft()
{
	
	TransferValue(TRUE);
	if ( GetCol () > 1 ) {
		int CurrentCol = GetCol();
		CurrentCol --;
		SetCol (CurrentCol);
		TransferValue (FALSE);
		if (!GetColIsVisible (CurrentCol))
			 SetLeftCol (CurrentCol);
	}
 return TRUE;


}


BOOL CGrid ::GoRight()
{
	
	TransferValue(TRUE);
	if ( GetCol () < GetCols() - 1 ) {
		int CurrentCol = GetCol ();
		CurrentCol++;
		SetCol (CurrentCol);
		TransferValue (FALSE);
		if (!GetColIsVisible (CurrentCol))
			 SetLeftCol (CurrentCol);
		
	}
	
	return TRUE;
}



BOOL CGrid ::TransferValue(BOOL ToGrid)
{
	CString sText;

	if (ToGrid) { //Transfer value to Grid from Edit Box
		SetText(m_GridData  );
	} else {
		m_GridData  = GetText ();
		SetBackColorSel  (RGB(0,255,255));
	}
	return TRUE;
}



BOOL CGrid ::OnKeyPressGrid(short FAR* KeyAscii) 
{

	   switch ( (int) * KeyAscii) {

			case  VK_BACK : //Backspace - delete the last character
				  m_GridData.Delete  (m_GridData.GetLength ()-1,1);
		          break;
			default :
				  m_GridData = m_GridData + (TCHAR *) KeyAscii;
			      break;
	   }
	   TransferValue (TRUE);
}


CGrid ::OnClickGrid()
{

	TransferValue (FALSE);
	 
}


void CGrid::OnEnterCell()
{
	TransferValue (FALSE);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?