📄 rxgrid.cpp
字号:
// RxGrid.cpp : implementation file
//
#include "stdafx.h"
#include "EasyTrade.h"
#include "RxGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRxGrid
CRxGrid::CRxGrid()
{
BEditing=false;
}
CRxGrid::~CRxGrid()
{
}
BEGIN_MESSAGE_MAP(CRxGrid, CListCtrl)
//{{AFX_MSG_MAP(CRxGrid)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRxGrid message handlers
void CRxGrid::SetDataBase(CString Record, long adCmd)
{
rst.Open(Record,adCmd);
CString sFieldName;
for(int m=0;m<rst.GetFieldCount();m++)
{
sFieldName=rst.GetFieldName(m);
this->InsertColumn(m,sFieldName);
}
this->AddCellValue(rst);
}
void CRxGrid::AddCellValue(CRxRecordset rs)
{
CString sFieldName;
int i,m;
rs.MoveFirst();
this->DeleteAllItems();
for(i=0;i<rs.GetRecordCount();i++)
{
this->InsertItem(i,"");
}
for(i=0;i<rs.GetRecordCount();i++)
{
rs.Move(i);
for(m=0;m<rs.GetFieldCount();m++)
{
sFieldName=rs.GetFieldName(m);
this->SetItemText(i,m,rs.GetFieldValue(sFieldName));
}
}
for(m=0;m<rs.GetFieldCount();m++)
{
this->SetColumnWidth(m,LVSCW_AUTOSIZE_USEHEADER );
}
}
void CRxGrid::ReadOnly(bool bReadOnly)
{
m_bReadOnly=bReadOnly;
}
bool CRxGrid::BeginEdit(int Row, int Col)
{
if(m_bReadOnly==true)
return false;
CRect rect;
CString sText;
if(this->GetSubItemRect(Row,Col,LVIR_LABEL,rect)==false)
return false;
sText=this->GetItemText(Row,Col);
m_Edit.MoveWindow(rect);
m_Edit.SetWindowText(sText);
m_Edit.ShowWindow(SW_SHOW);
m_Edit.SetSel(0,-1);
m_Edit.SetFocus();
this->GetCols();
::SendMessage(this->GetParent()->GetSafeHwnd(),DIY_SETFOCUS,NULL,NULL);
return true;
}
bool CRxGrid::EndEdit()
{
CString sLabel;
m_Edit.GetWindowText(sLabel);
this->SetItemText(m_Row,m_Col,sLabel);
m_Edit.ShowWindow(SW_HIDE);
BEditing=false;
::SendMessage(this->GetParent()->GetSafeHwnd(),DIY_KILLFOCUS,NULL,NULL);
return true;
}
int CRxGrid::GetCol()
{
return m_Col;
}
int CRxGrid::GetRow()
{
return m_Row;
}
int CRxGrid::GetRows()
{
return this->GetItemCount();
}
int CRxGrid::GetCols()
{
int cols[255];
this->GetColumnOrderArray(&cols[0]);
for(int m=0;m<255;m++)
{
if(cols[m]==-858993460)
break;
}
return m;
}
bool CRxGrid::SetRow(int nRow)
{
this->EndEdit();
this->m_Row=nRow;
this->BeginEdit(m_Row,m_Col);
return true;
}
bool CRxGrid::SetCol(int nCol)
{
this->EndEdit();
this->m_Col=nCol;
this->BeginEdit(m_Row,m_Col);
return true;
}
void CRxGrid::MoveNextItem()
{
CSize size;
int ncol;
ncol=GetCol();
if(ncol<GetCols()-1)
{
size.cx=20*ncol;
this->Scroll(size);
SetCol(ncol+1);
}
else
{
size.cx=-20*m_Col;
this->Scroll(size);
if(GetRow()<GetRows()-1)
{
m_Col=0;
SetRow(GetRow()+1);
}
else
{
this->InsertItem(GetRow()+1,"");
this->SetCol(0);
this->SetRow(m_Row+1);
}
}
}
BOOL CRxGrid::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CListCtrl::PreTranslateMessage(pMsg);
}
void CRxGrid::PreSubclassWindow() //设置网格的风格
{
// TODO: Add your specialized code here and/or call the base class
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); //扁平风格显示滚动条
int style=WS_CHILD|WS_CLIPSIBLINGS|WS_EX_TOOLWINDOW|WS_BORDER;
m_Edit.Create(style,CRect(0,0,0,0),this,ID_CELL);
CListCtrl::PreSubclassWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -