怎样让CListCtrl具有编辑的功能,不光是显示?? 怎样让CListCtrl具有编辑的功能,不光是显示?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 简单。建立一个CEdit控件。然后点那一个单元格连续两次就移动到那里。 添加一个Edit控件,其位置和大小随选择List项的改变而改变,编辑框内输入的内容按回车键后成为list内容 m_listctrl 为listctrl控件 m_listedit为移动到listctrl控件的edit其中OnClickListStat为listctrl的单击事件OnKillfocusEditStat() 为edit的OnKillfocus。。事件其他的自己试试,如果不行发短消息给我(加帖子的网址)CString CStat::GetItemText(HWND hWnd, int nItem, int nSubItem) const{ LVITEM lvi; memset(&lvi, 0, sizeof(LVITEM)); lvi.iSubItem = nSubItem; CString str; int nLen = 128; int nRes; do { nLen *= 2; lvi.cchTextMax = nLen; lvi.pszText = str.GetBufferSetLength(nLen); nRes = (int)::SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi); } while (nRes == nLen-1); str.ReleaseBuffer(); return str; }void CStat::OnClickListStat(NMHDR* pNMHDR, LRESULT* pResult) { HWND hWnd1 = ::GetDlgItem (m_hWnd,IDC_LIST_STATCAR); LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR; RECT rect; //取得行号 nItem = temp->iItem; //取得列号 nSubItem = temp->iSubItem; RECT rect1,rect2,rect3; ListView_GetSubItemRect(hWnd1,temp->iItem,temp->iSubItem,LVIR_BOUNDS,&rect); ::GetWindowRect(temp->hdr.hwndFrom,&rect1); ::GetWindowRect(m_hWnd,&rect2); m_listctrl.GetWindowRect(&rect3); ScreenToClient(&rect3); int x=rect1.left-rect2.left; int y=rect1.top-rect2.top; m_listedit.SetWindowPos(NULL,rect.left+x+3,rect.top+rect3.top+2 ,rect.right-rect.left - 3,rect.bottom-rect.top -1,NULL); m_listedit.ShowWindow(SW_SHOW); m_listedit.SetFocus(); m_listedit.SetWindowText(str); *pResult = 0;}void CStat::OnKillfocusEditStat() { CString strtemp; m_listedit.GetWindowText(strtemp); int count = atoi(strtemp); strtemp = inttostr(count); if(strtemp=="0"||strtemp=="+0"||strtemp=="-0") strtemp = ""; SetCell(m_listctrl.GetSafeHwnd(),strtemp,nItem,nSubItem); m_listedit.ShowWindow(SW_HIDE); CString str; int countnum =0; for(int i = 0;i<m_listctrl.GetItemCount()-1;i++) { str = m_listctrl.GetItemText(i,nSubItem); countnum = atoi(str)+countnum; } SetCell(m_listctrl.GetSafeHwnd(),inttostr(countnum),m_listctrl.GetItemCount()-1,nSubItem); }void CStat::SetCell(HWND hWnd1, CString value, int nRow, int nCol){ TCHAR szString [256]; wsprintf(szString,value ,0); LVITEM lvItem; lvItem.mask = LVIF_TEXT; lvItem.iItem = nRow; lvItem.pszText = szString; lvItem.iSubItem = nCol; if(nCol >0) ::SendMessage(hWnd1,LVM_SETITEM, (WPARAM)0,(WPARAM)&lvItem); else ListView_InsertItem(hWnd1,&lvItem); } 请看http://www.codeproject.com/listctrl/中有这样一个示例http://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp例子挺好的,我刚刚截取了一些代码,用了用:) 我有现成的,不光是可以编辑(鼠标一点就可以编辑),还可以添加像combox控件一样的功能不过这种问题20分实在是....... 从CODEPROJECT上下载一个例子程序多好,什么功能都有,还用这样费劲,而且想研究一下,可以读他们的代码,很好的。 关于大量数据收发问题? 想做个自动登陆器 关于insertAdjacentHTML函数的问题! 如何分割MDI主窗口?(用MFC实现) 用smpp协议如何发中文的短消息?用smpp协议能从联通发到移动的手机吗,还是必须用sgip协议? 求大侠调试个VC程序 VC 编译问题!! 请问如何编程注册ODBC数据源。 难!关于在任务栏隐藏窗口的问题 ADO连数据库 记录集指针定义在哪里 连接指针定义在哪里? 登录对话框Login的问题 文件夹选择对话框?
其中OnClickListStat为listctrl的单击事件
OnKillfocusEditStat() 为edit的OnKillfocus。。事件
其他的自己试试,如果不行发短消息给我(加帖子的网址)CString CStat::GetItemText(HWND hWnd, int nItem, int nSubItem) const
{
LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.iSubItem = nSubItem;
CString str;
int nLen = 128;
int nRes;
do
{
nLen *= 2;
lvi.cchTextMax = nLen;
lvi.pszText = str.GetBufferSetLength(nLen);
nRes = (int)::SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)nItem,
(LPARAM)&lvi);
} while (nRes == nLen-1);
str.ReleaseBuffer();
return str;
}void CStat::OnClickListStat(NMHDR* pNMHDR, LRESULT* pResult)
{
HWND hWnd1 = ::GetDlgItem (m_hWnd,IDC_LIST_STATCAR);
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
RECT rect;
//取得行号
nItem = temp->iItem;
//取得列号
nSubItem = temp->iSubItem;
RECT rect1,rect2,rect3;
ListView_GetSubItemRect(hWnd1,temp->iItem,temp->iSubItem,LVIR_BOUNDS,&rect);
::GetWindowRect(temp->hdr.hwndFrom,&rect1);
::GetWindowRect(m_hWnd,&rect2);
m_listctrl.GetWindowRect(&rect3);
ScreenToClient(&rect3);
int x=rect1.left-rect2.left;
int y=rect1.top-rect2.top;
m_listedit.SetWindowPos(NULL,rect.left+x+3,rect.top+rect3.top+2 ,rect.right-rect.left - 3,rect.bottom-rect.top -1,NULL);
m_listedit.ShowWindow(SW_SHOW);
m_listedit.SetFocus();
m_listedit.SetWindowText(str);
*pResult = 0;
}void CStat::OnKillfocusEditStat()
{
CString strtemp;
m_listedit.GetWindowText(strtemp);
int count = atoi(strtemp);
strtemp = inttostr(count);
if(strtemp=="0"||strtemp=="+0"||strtemp=="-0")
strtemp = "";
SetCell(m_listctrl.GetSafeHwnd(),strtemp,nItem,nSubItem);
m_listedit.ShowWindow(SW_HIDE);
CString str;
int countnum =0;
for(int i = 0;i<m_listctrl.GetItemCount()-1;i++)
{
str = m_listctrl.GetItemText(i,nSubItem);
countnum = atoi(str)+countnum;
}
SetCell(m_listctrl.GetSafeHwnd(),inttostr(countnum),m_listctrl.GetItemCount()-1,nSubItem);
}void CStat::SetCell(HWND hWnd1, CString value, int nRow, int nCol)
{
TCHAR szString [256];
wsprintf(szString,value ,0);
LVITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iItem = nRow;
lvItem.pszText = szString;
lvItem.iSubItem = nCol;
if(nCol >0)
::SendMessage(hWnd1,LVM_SETITEM, (WPARAM)0,(WPARAM)&lvItem);
else
ListView_InsertItem(hWnd1,&lvItem);
}
中有这样一个示例http://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp例子挺好的,我刚刚截取了一些代码,用了用:)
不过这种问题20分实在是.......