请问有关ListCtrl的可编辑的问题? 请问如何使ListCtrl的某行的某项处于编辑状态.程序可得到编辑完后按回车后的结果? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 动态在该单元匡 创建CEdit控件, Examplevoid CMyView::OnInitialUpdate() { CView::OnInitialUpdate(); // dynamically create an edit control on the view CEdit* pEdit = new CEdit; pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, CRect(10, 10, 100, 100), this, 1);}MSDN里面的例子。我强烈建议你安装MSDN,可以说出了少数几个超级NB别人离了MSDN编不了VC的 好像楼上的说得不是很清楚.我在MSDN里没有找到,请能否全面详细一点,谢谢! 先继承CListCtrl和CEdit类,在CListCtrl中响应单击等你需要的事件,在其中显示CEdit,在CEdit中响应失去焦点和回车消息如:void CEditListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult) { LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR; // TODO: Add your control notification handler code here if (EditIt(temp->iItem, temp->iSubItem)) { m_nItem = temp->iItem; m_nSubItem = temp->iSubItem; } *pResult = 0; }void CEditListCtrl::EditItem(int iItem, int iSubItem){#define IDC_EDITCTRL 0x1234 if ((iItem < 0) || (iSubItem < 1) || (iSubItem >= m_nColumns)) { return ; } CRect rect; // 编辑框的。 GetSubItemRect(iItem, iSubItem, LVIR_BOUNDS, rect); CRect rcClient; GetClientRect(rcClient); // 以下设置位置。 if ((rect.left < 0) || (rect.left > rcClient.right)) { // 在外。 ScrollIt(rect.left, 0); rect.left -= rect.left; } else if (rect.bottom > rcClient.bottom) { ScrollIt(0, rect.bottom); this->SetFocus(); return ; } else if (rect.bottom <= 20) { ScrollIt(0, -rect.bottom); this->SetFocus(); return ; } rect.right = rect.left + GetColumnWidth(iSubItem); if (rect.right > rcClient.right) { rect.right = rcClient.right; } DWORD dwStyle; // 编辑框的风格。 dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL; CEdit *pEdit = new CMyEditCtrl(iItem, iSubItem, GetItemText(iItem, iSubItem)); if (pEdit == NULL) { AfxMessageBox(_T("Memory Exhausted!")); exit(1); } pEdit->Create( dwStyle, rect, this, IDC_EDITCTRL ); // 文字或数字全部选中。 pEdit->SetSel(0, -1);}void CMyEditCtrl::OnKillFocus(CWnd* pNewWnd) { CEdit::OnKillFocus(pNewWnd); // TODO: Add your message handler code here CString strTemp; GetWindowText(strTemp); LV_DISPINFO lvDispInfo; // 将要显示的信息。 lvDispInfo.hdr.hwndFrom = GetParent()->m_hWnd; lvDispInfo.hdr.idFrom = GetDlgCtrlID(); lvDispInfo.hdr.code = LVN_ENDLABELEDIT; lvDispInfo.item.mask = LVIF_TEXT; lvDispInfo.item.iItem = m_iItem; lvDispInfo.item.iSubItem = m_iSubItem; // 按了ESC就显示原来的信息。 lvDispInfo.item.pszText = m_bIsEsc ? LPTSTR((LPCTSTR)m_strText): LPTSTR((LPCTSTR)strTemp); lvDispInfo.item.cchTextMax = m_bIsEsc ? m_strText.GetLength() : strTemp.GetLength(); GetParent()->GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&lvDispInfo); // 改吧。 DestroyWindow(); }void CMyEditCtrl::OnNcDestroy() { CEdit::OnNcDestroy(); // TODO: Add your message handler code here // 编辑框在此销毁。 delete this;}回车消息,你自己响应。 Linux 设备驱动(第三版)。chm版本 程序在运行过程中图标被改变,请问各位大侠是什么原因啊? 100分求一个 非阻塞Connect的例子 大虾们帮帮忙 Active中如何得到环境句柄的问题,马上给分!!!(关于VC.net的) 关于ODBC的数据库编程 vc怎样调用com组件? ADO 与 DAO 的问题 在桌面上画线的问题 ATL线程使用、包容的问题? Win98的任务栏图标区(系统托盘)是否支持256色图标,Win95呢? 以前可以安装并能正常运行的RedHat Linux7.0现在不能安装了,请教各位高手是什么原因?谢谢! 关于串口通信的重叠结构
{
CView::OnInitialUpdate();
// dynamically create an edit control on the view
CEdit* pEdit = new CEdit;
pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CRect(10, 10, 100, 100), this, 1);
}MSDN里面的例子。
我强烈建议你安装MSDN,可以说出了少数几个超级NB别人离了MSDN编不了VC的
{
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
// TODO: Add your control notification handler code here
if (EditIt(temp->iItem, temp->iSubItem))
{
m_nItem = temp->iItem;
m_nSubItem = temp->iSubItem;
}
*pResult = 0;
}
void CEditListCtrl::EditItem(int iItem, int iSubItem)
{
#define IDC_EDITCTRL 0x1234 if ((iItem < 0) || (iSubItem < 1) || (iSubItem >= m_nColumns))
{
return ;
} CRect rect; // 编辑框的。
GetSubItemRect(iItem, iSubItem, LVIR_BOUNDS, rect);
CRect rcClient;
GetClientRect(rcClient);
// 以下设置位置。
if ((rect.left < 0) || (rect.left > rcClient.right))
{ // 在外。
ScrollIt(rect.left, 0);
rect.left -= rect.left;
}
else if (rect.bottom > rcClient.bottom)
{
ScrollIt(0, rect.bottom);
this->SetFocus();
return ;
}
else if (rect.bottom <= 20)
{
ScrollIt(0, -rect.bottom);
this->SetFocus();
return ;
} rect.right = rect.left + GetColumnWidth(iSubItem);
if (rect.right > rcClient.right)
{
rect.right = rcClient.right;
} DWORD dwStyle; // 编辑框的风格。
dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL; CEdit *pEdit = new CMyEditCtrl(iItem, iSubItem, GetItemText(iItem, iSubItem));
if (pEdit == NULL)
{
AfxMessageBox(_T("Memory Exhausted!"));
exit(1);
}
pEdit->Create( dwStyle, rect, this, IDC_EDITCTRL );
// 文字或数字全部选中。
pEdit->SetSel(0, -1);
}
void CMyEditCtrl::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
CString strTemp;
GetWindowText(strTemp);
LV_DISPINFO lvDispInfo; // 将要显示的信息。 lvDispInfo.hdr.hwndFrom = GetParent()->m_hWnd;
lvDispInfo.hdr.idFrom = GetDlgCtrlID();
lvDispInfo.hdr.code = LVN_ENDLABELEDIT;
lvDispInfo.item.mask = LVIF_TEXT;
lvDispInfo.item.iItem = m_iItem;
lvDispInfo.item.iSubItem = m_iSubItem;
// 按了ESC就显示原来的信息。
lvDispInfo.item.pszText = m_bIsEsc ? LPTSTR((LPCTSTR)m_strText): LPTSTR((LPCTSTR)strTemp);
lvDispInfo.item.cchTextMax = m_bIsEsc ? m_strText.GetLength() : strTemp.GetLength(); GetParent()->GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(),
(LPARAM)&lvDispInfo); // 改吧。
DestroyWindow();
}
void CMyEditCtrl::OnNcDestroy()
{
CEdit::OnNcDestroy();
// TODO: Add your message handler code here
// 编辑框在此销毁。
delete this;
}
回车消息,你自己响应。