📄 rxgrid.cpp
字号:
// RxGrid.cpp : implementation file
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "RxGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CRxGrid
CRxGrid::CRxGrid()
{
this->bEditing=false; //处于无编辑状态
this->IsCanEdit=true;
}
CRxGrid::~CRxGrid()
{
}
BEGIN_MESSAGE_MAP(CRxGrid, CListCtrl)
//{{AFX_MSG_MAP(CRxGrid)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CRxGrid::OnLButtonDown(UINT nFlags, CPoint point)
{
if (this->IsCanEdit==false)
return;
POSITION pos;
bool bSelected=false;
//检查是否正处于编辑状态
if(bEditing==true)
goto leave;
//检查是否有单元被选中
pos=this->GetFirstSelectedItemPosition();
if(pos)
{
//得到被单击的单元
LVHITTESTINFO testinfo;
testinfo.pt.x=point.x;
testinfo.pt.y=point.y;
testinfo.flags=LVHT_ONITEMLABEL; //单击的必须是标题
if(this->SubItemHitTest(&testinfo)<0)
goto leave;
this->m_Col=testinfo.iSubItem ; //取得行与列
this->m_Row=testinfo.iItem;
//检查该表项是否被选中,没被选中不能编辑
while(pos)
if(m_Row==this->GetNextSelectedItem(pos))
{
bSelected=true;
break;
}
if(bSelected=false)
goto leave;
bEditing=BeginEdit(m_Row,m_Col);
return;
}
leave:
CListCtrl::OnLButtonDown(nFlags, point);
}
int CRxGrid::BeginEdit(int Row ,int Col)
{
CRect rct;
if(this->GetSubItemRect(Row,Col,LVIR_LABEL,rct)==false)
return false;
int style=WS_CHILD|WS_CLIPSIBLINGS|WS_EX_TOOLWINDOW|WS_BORDER;
m_Edit.Create(style,rct,this,CELLEDIT);
m_Edit.ShowWindow(SW_SHOW);
CString CellText=GetItemText(Row,Col);
m_Edit.DataBase=Database;
m_Edit.Field=Field;
m_Edit.assn=Assn;
m_Edit.GridParent=this->GetParent();
try{
m_Edit.SetWindowText(CellText);
}
catch(...)
{
goto ResumeNext;
}
ResumeNext: m_Edit.SetFocus();
m_Edit.SetSel(0,-1);
return true;
}
void CRxGrid::EndEdit(bool bValidate)
{
if(bValidate)
{
CString CellText;
try{
m_Edit.GetWindowText(CellText);
SetItemText(m_Row,m_Col,CellText);
}
catch(...)
{
goto ResameNext;
}
}
ResameNext: m_Edit.DestroyWindow();
bEditing=false;
}
int CRxGrid::GetRow()
{
return this->m_Row;
}
/*
返回当前所在单元格的列标
*/
int CRxGrid::GetCol()
{
return this->m_Col;
}
BOOL CRxGrid::PreTranslateMessage(MSG* pMsg)
{
return CListCtrl::PreTranslateMessage(pMsg);
}
void CRxGrid::SetDataBase(CString sDataBaseName)
{
this->Database=sDataBaseName;
this->m_Edit.DataBase=sDataBaseName;
}
void CRxGrid::SetAssn(bool bAssn)
{
this->Assn=bAssn;
this->m_Edit.assn=bAssn;
}
void CRxGrid::SetField(CString sField)
{
this->Field=sField;
this->m_Edit.Field=sField;
}
void CRxGrid::ClearGrid()
{
this->Clear();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -