📄 tablelist.cpp
字号:
//********* 列表控件类 *********//
#include "stdafx.h"
#include "TableList.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTableList::CTableList()
{
m_pListCtrl=NULL; // 列表控件指针清空
m_nCols=0; // 列的数目清零
m_nRows=0; // 行的数目清零
sHead.RemoveAll(); // 表头字符串数组
}
CTableList::~CTableList()
{
m_pListCtrl=NULL; // 列表控件指针清空
}
// 设置行的数目
void CTableList::SetRows(int Rows)// 设置行的数目
{
if(m_pListCtrl==NULL)
{
MessageBox(NULL,_T("没有设置控件指针,请先给变量m_pListCtrl赋值!"),_T("列表控件—设置行数目"),MB_ICONINFORMATION);
return;
}
for(int i=0;i<m_nRows;i++)
m_pListCtrl->DeleteItem(0);
for ( i=0;i<Rows;i++)
{
m_pListCtrl->InsertItem(i,_T(""));
for(int j=0;j<m_nCols;j++)
m_pListCtrl->SetItemText(i,j,_T(""));
}
m_nRows=Rows;
m_pListCtrl->SetExtendedStyle(LVS_EX_GRIDLINES|LVN_ENDLABELEDIT|LVS_EX_FULLROWSELECT);
m_pListCtrl->SetTextColor(RGB(0,200,0));
m_pListCtrl->SetTextBkColor(RGB(0,0,0));
m_pListCtrl->SetBkColor(RGB(168,168,168));
}
// 设置列的数目
void CTableList::SetCols(int Cols)// 设置列的数目
{
/* if(m_pListCtrl==NULL)
{
MessageBox(NULL,_T("没有设置控件指针,请先给变量m_pListCtrl赋值!"),_T("列表控件—设置列数目"),MB_ICONINFORMATION);
return;
}
for(int i=0;i<m_nCols;i++) // 删除以前的列
m_pListCtrl->DeleteColumn(0);
for(i=0;i<Cols;i++)
{
m_pListCtrl->InsertColumn(i,_T(""),LVCFMT_LEFT,80,i);
}
m_nCols=Cols;
*/
}
// 设置单元格的信息
void CTableList::SetTableText(int nRow, int nCol, CString sText)
{
if(m_pListCtrl==NULL)
{
MessageBox(NULL,_T("没有设置控件指针,请先给变量m_pListCtrl赋值!"),_T("列表控件—设置单元格信息"),MB_ICONINFORMATION);
return;
}
CString str;
if(nCol>=m_nCols)
{
str.Format(_T("指定的表单列超出范围!\r\n指定的值: %d 表单列数: %d"),nCol,m_nCols-1);
MessageBox(NULL,str,_T("列表控件—设置单元格信息"),MB_ICONINFORMATION);
return;
}
if(nRow>=m_nRows)
{
str.Format(_T("指定的表单行超出范围!\r\n指定的值: %d 表单行数: %d"),nRow,m_nRows-1);
MessageBox(NULL,str,_T("列表控件—设置单元格信息"),MB_ICONINFORMATION);
return;
}
m_pListCtrl->SetItemText(nRow,nCol,sText);
}
// 获得单元格的信息
CString CTableList::GetTableText(int nRow, int nCol)
{
if(m_pListCtrl==NULL)
{
MessageBox(NULL,_T("没有设置控件指针,请先给变量m_pListCtrl赋值!"),_T("列表控件—获取单元格信息"),MB_ICONINFORMATION);
return _T("");
}
CString str;
if(nCol>=m_nCols)
{
str.Format(_T("指定的表单列超出范围!\r\n指定的值: %d 表单列数: %d"),nCol,m_nCols-1);
MessageBox(NULL,str,_T("列表控件—获取单元格信息"),MB_ICONINFORMATION);
return _T("");
}
if(nRow>=m_nRows)
{
str.Format(_T("指定的表单行超出范围!\r\n指定的值: %d 表单行数: %d"),nRow,m_nRows-1);
MessageBox(NULL,str,_T("列表控件—获取单元格信息"),MB_ICONINFORMATION);
return _T("");
}
str=m_pListCtrl->GetItemText(nRow,nCol);
return str;
}
// 设置表单的头信息
void CTableList::SetTableHead(int nCol, CString sText,int Width) // 设置表单的头信息
{
if(m_pListCtrl==NULL)
{
MessageBox(NULL,_T("没有设置控件指针,请先给变量m_pListCtrl赋值!"),_T("列表控件—设置表单的头信息"),MB_ICONINFORMATION);
return ;
}
/*
*/ //m_pListCtrl->DeleteColumn(nCol);
sHead.Add(sText);
m_nCols++;
m_pListCtrl->InsertColumn(nCol,sText,LVCFMT_RIGHT,Width,nCol);
}
// 获得头信息
CString CTableList::GetHeadText(int Col)
{
CString str;
if(Col>=m_nCols)
{
str.Format(_T("指定的表单列超出范围!\r\n指定的值: %d 表单列数: %d"),Col,m_nCols-1);
MessageBox(NULL,str,_T("列表控件—获得表单的头信息"),MB_ICONINFORMATION);
return _T("");
}
str=sHead.GetAt(Col);
return str;
}
// 清除所有单元格的显示内容
void CTableList::ClearAllItems()
{
for(int i=0;i<m_nRows;i++)
for(int j=0;j<m_nCols;j++)
SetTableText(i,j,_T(""));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -