iItem; m_pointIndexOfCell.y = pNMListView->iSubItem; //保存指定单元格的索引int iRow = pNMListView->iItem; ..._mfc listcontrol 添加按钮">
赞
踩
CRect rcCellRect;
CString csCellData = "";
NM_LISTVIEW * pNMListView = (NM_LISTVIEW*)pNMHDR;
m_pointIndexOfCell.x = pNMListView->iItem;
m_pointIndexOfCell.y = pNMListView->iSubItem; //保存指定单元格的索引
int iRow = pNMListView->iItem;
int iCol = pNMListView->iSubItem;
m_iCurRow = pNMListView->iItem;
m_iCurCol = pNMListView->iSubItem;
CRect crTemp;
bool needSave = true;
bool ComneedSave = true;
//在指定列插入Combo Box
if (iCol == 0 ||iCol ==1)
{
m_ctrlComboCell.SetParent(&m_Picture);
m_Picture.GetSubItemRect(iRow, 2, LVIR_LABEL, rcCellRect);
rcCellRect.SetRect(rcCellRect.left, rcCellRect.top, rcCellRect.left + m_Picture.GetColumnWidth(2), rcCellRect.bottom);
m_ctrlComboCell.MoveWindow(&rcCellRect);
m_ctrlComboCell.ShowWindow(SW_SHOW);
m_ctrlComboCell.SetFocus(); //设置焦点
m_Btn2.SetParent(&m_Picture);
m_Picture.GetSubItemRect(iRow, 3, LVIR_LABEL, rcCellRect);
rcCellRect.SetRect(rcCellRect.left, rcCellRect.top, rcCellRect.left + m_Picture.GetColumnWidth(3), rcCellRect.bottom);
m_Btn2.MoveWindow(&rcCellRect);
m_Btn2.ShowWindow(SW_SHOW);
m_Btn2.SetFocus();
}
else
{
if (2 == iCol)
{
if (m_ctrlComboCell.m_hWnd == NULL)
{
ComneedSave = true;
m_ctrlComboCell.Create(WS_CHILD | WS_VISIBLE | CBS_SORT | CBS_DROPDOWN | CBS_OEMCONVERT, CRect(0, 0, 40, 40), this, 0);
m_ctrlComboCell.SetFont(this->GetFont(), FALSE);
}
m_ctrlComboCell.SetParent(&m_Picture);
m_Picture.GetSubItemRect(iRow, iCol, LVIR_LABEL, rcCellRect);
rcCellRect.SetRect(rcCellRect.left, rcCellRect.top, rcCellRect.left + m_Picture.GetColumnWidth(iCol), rcCellRect.bottom);
m_ctrlComboCell.MoveWindow(&rcCellRect);
m_ctrlComboCell.ShowWindow(SW_SHOW);
m_ctrlComboCell.SetFocus(); //设置焦点
m_Btn2.SetParent(&m_Picture);
m_Picture.GetSubItemRect(iRow, iCol+1, LVIR_LABEL, rcCellRect);
rcCellRect.SetRect(rcCellRect.left, rcCellRect.top, rcCellRect.left + m_Picture.GetColumnWidth(iCol+1), rcCellRect.bottom);
m_Btn2.MoveWindow(&rcCellRect);
m_Btn2.ShowWindow(SW_SHOW);
m_Btn2.SetFocus();
}
else
{
//m_ctrlComboCell.ShowWindow(SW_HIDE);
}
if (iCol == 3)
{
m_Btn2.SetParent(&m_Picture);
m_Picture.GetSubItemRect(iRow, iCol, LVIR_LABEL, rcCellRect);
rcCellRect.SetRect(rcCellRect.left, rcCellRect.top, rcCellRect.left + m_Picture.GetColumnWidth(iCol), rcCellRect.bottom);
m_Btn2.MoveWindow(&rcCellRect);
m_Btn2.ShowWindow(SW_SHOW);
m_Btn2.SetFocus();
m_ctrlComboCell.SetParent(&m_Picture);
m_Picture.GetSubItemRect(iRow, iCol-1, LVIR_LABEL, rcCellRect);
rcCellRect.SetRect(rcCellRect.left, rcCellRect.top, rcCellRect.left + m_Picture.GetColumnWidth(iCol - 1), rcCellRect.bottom);
m_ctrlComboCell.MoveWindow(&rcCellRect);
m_ctrlComboCell.ShowWindow(SW_SHOW);
m_ctrlComboCell.SetFocus(); //设置焦点
}
else
{
//m_Btn2.ShowWindow(SW_HIDE);
}
}
效果图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。