www.gusucode.com > VC++毕业设计-库存管理系统(Access)-源码程序 > VC++毕业设计-库存管理系统(Access)-源码程序/code/源程序/ExtendEdit_Grid.cpp

    //Download by http://www.NewXing.com
// ExtendEdit_Grid.cpp : implementation file
//

#include "stdafx.h"
#include "商品库存管理系统.h"
#include "ExtendEdit_Grid.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CExtendEdit_Grid

CExtendEdit_Grid::CExtendEdit_Grid()
{
}

CExtendEdit_Grid::~CExtendEdit_Grid()
{
}


BEGIN_MESSAGE_MAP(CExtendEdit_Grid, CListCtrl)
	//{{AFX_MSG_MAP(CExtendEdit_Grid)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExtendEdit_Grid message handlers

void CExtendEdit_Grid::SetRecordset(_RecordsetPtr pRst)
{
	this->rst=pRst;
	//添加列标题
	CString FieldName;
	for(int j=0;j<rst->GetFields()->GetCount();j++)
	{
		FieldName=(char*)(_bstr_t)rst->GetFields()->GetItem((long)j)->Name;
		InsertColumn(j,FieldName);
	}
	this->m_Cols=j;
	//添加行
	for(int i=0;i<theApp.GetRecordCount(rst);i++)
	{
		this->InsertItem(i,"");
	}
	//显示记录
	this->Refresh();
	//调整列宽
	for(j=0;j<rst->GetFields()->GetCount();j++)
	{
		SetColumnWidth(j,LVSCW_AUTOSIZE);
	}
}

void CExtendEdit_Grid::Refresh()
{
	if(theApp.GetRecordCount(rst)<0)
		Clear();
	else
	{
		this->DeleteAllItems();
		for(int i=0;i<theApp.GetRecordCount(rst);i++)
		{
			this->InsertItem(i,"");
		}

		CString CellText;
		for( i=0;i<theApp.GetRecordCount(rst);i++)
		{
			rst->MoveFirst();
			rst->Move(i);
			for(int j=0;j<rst->GetFields()->GetCount();j++)
			{
				CellText=(char*)(_bstr_t)rst->GetFields()->GetItem((long)j)->Value;
				SetItemText(i,j,CellText);
			}
		}	
	}
		
}

void CExtendEdit_Grid::Clear()
{
	this->DeleteAllItems();	
}

void CExtendEdit_Grid::PreSubclassWindow() 
{
	this->ModifyStyle(LVS_EDITLABELS,0L); //标题栏不可编辑
	this->ModifyStyle(0L,LVS_REPORT);     
	this->ModifyStyle(0L,LVS_SHOWSELALWAYS);    //高亮显示被选中项
	this->SetExtendedStyle(LVS_EX_FULLROWSELECT| //允许整行选中
		LVS_EX_HEADERDRAGDROP|  //允许整列拖动
		LVS_EX_GRIDLINES|     //画出网格线
		LVS_EX_ONECLICKACTIVATE|     //单击选中项
		LVS_EX_FLATSB);    //扁平风格显示滚动条
	
	CListCtrl::PreSubclassWindow();
}

int CExtendEdit_Grid::GetColumnCount()
{
	return m_Cols;
}

void CExtendEdit_Grid::SetColumnCount(int nCol)
{
	m_Cols=nCol;
}

void CExtendEdit_Grid::DeleAllCol()
{
	int cols=this->GetColumnCount();
	for(int i=0;i<=cols+1;i++)
	{
		this->DeleteColumn(0);
	}
}