?? rxgrid.cpp
字號:
// RxGrid.cpp : implementation file
//
#include "stdafx.h"
#include "htglxt.h"
#include "RxGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// RxGrid
RxGrid::RxGrid()
{
BEditing=false;
}
RxGrid::~RxGrid()
{
}
BEGIN_MESSAGE_MAP(RxGrid, CListCtrl)
//{{AFX_MSG_MAP(RxGrid)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// RxGrid message handlers
void RxGrid::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); //扁平風格顯示滾動條
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();
}
void RxGrid::OnLButtonDown(UINT nFlags, CPoint point)
{
bool bSelected=false;
if(BEditing==true) //已經有單元格被編輯
goto End;
LVHITTESTINFO testinfo;
testinfo.pt.x=point.x;
testinfo.pt.y=point.y;
testinfo.flags=LVHT_ONITEMLABEL;
if(this->SubItemHitTest(&testinfo)<0)
goto End;
m_Col=testinfo.iSubItem;
m_Row=testinfo.iItem;
BEditing=BeginEdit(m_Row,m_Col); //編輯單元格
this->OnRButtonDblClk(nFlags,point);
return;
End: CListCtrl::OnLButtonDown(nFlags, point);
}
bool RxGrid::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 RxGrid::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 RxGrid::GetCol()
{
return m_Col;
}
int RxGrid::GetRow()
{
return m_Row;
}
int RxGrid::GetRows()
{
return this->GetItemCount();
}
int RxGrid::GetCols()
{
int cols[255];
this->GetColumnOrderArray(&cols[0]);
for(int m=0;m<255;m++)
{
if(cols[m]==-858993460)
break;
}
return m;
}
bool RxGrid::SetRow(int nRow)
{
this->EndEdit();
this->m_Row=nRow;
this->BeginEdit(m_Row,m_Col);
return true;
}
bool RxGrid::SetCol(int nCol)
{
this->EndEdit();
this->m_Col=nCol;
this->BeginEdit(m_Row,m_Col);
return true;
}
BOOL RxGrid::PreTranslateMessage(MSG* pMsg)
{
return CListCtrl::PreTranslateMessage(pMsg);
}
void RxGrid::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);
}
}
}
void RxGrid::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 RxGrid::ReadOnly(bool bReadOnly)
{
m_bReadOnly=bReadOnly;
}
void RxGrid::AddCellValue(RxRecordset 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 );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -