|
1.样式View:Report表格,list列表
2.设置风格:SetExtendedStyle
SetExtendedStyle函数的定义形式为:
DWORD SetExtendedStyle(DWORD dwNewStyle );
参数:dwNewStyle:CListCtrl的扩展样式(LVS_EX_GRIDLINES //绘制表格;LVS_EX_SUBITEMIMAGES//子项目图标列表;LVS_EX_CHECKBOXES //带复选框;LVS_EX_TRACKSELECT //自动换行;LVS_EX_HEADERDRAGDROP//报表头可以拖拽;LVS_EX_FULLROWSELECT //选择整行;LVS_EX_ONECLICKACTIVATE//单击激活;LVS_EX_TWOCLICKACTIVATE//双击激活;LVS_EX_FLATSB//扁平滚动条;LVS_EX_REGIONAL;LVS_EX_INFOTIP;LVS_EX_UNDERLINEHOT;LVS_EX_UNDERLINECOLD;LVS_EX_MULTIWORKAREAS//多工作区)
SetExtendedStyle函数的具体用法如例:
m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT );
3.滚动条位置Left Scrollbar:滚动条在左侧还是右侧
4.MFC的表格不允许编辑,如果想编辑只能在编辑开始事件中把单元格处理成Edit,在编辑结束后把edit的值更新到list里:
(1)首先属性Edit Labels设为true;
(2)增加事件响应函数:
ON_NOTIFY(NM_DBLCLK, IDC_LIST_COORD, &CCoordManageDlg::OnNMDblclkListCoord)
ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST_COORD, &CCoordManageDlg::OnLvnEndlabeleditListCoord)
双击事件:
void CCoordManageDlg::OnNMDblclkListCoord(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
*pResult = 0;
POSITION pos = m_listCoord.GetFirstSelectedItemPosition();
int nSel = m_listCoord.GetNextSelectedItem(pos);
if ( nSel >= 0 )
{
m_listCoord.SetFocus();
CEdit* pEdit = m_listCoord.EditLabel( nSel );
}
}
edit编辑结束事件
void CCoordManageDlg::OnLvnEndlabeleditListCoord(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
*pResult = 0;
CString strName = pDispInfo->item.pszText;
int nSel = pDispInfo->item.iItem;
m_listCoord.SetFocus();
if( ( ! strName.IsEmpty() ) && nSel >= 0 )
m_listCoord.SetItemText( nSel, 0, strName);
}
(5)点击表头,获取列头的编号
ON_NOTIFY(HDN_ITEMCLICK, 0, &CStartDlg::OnHdnItemclickListStartmonitor)
void CStartDlg::OnHdnItemclickListStartmonitor(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int nRow = pNMListView->iItem;
switch(nRow)
{
case 0:
break;
case 1:
break;
}
}
(6)获取当前选择项
POSITION pos = GetFirstSelectedItemPosition();
if (pos != NULL)
{
int iSubItem = GetNextSelectedItem(pos);
} |
|