vc中CListCtrl控件点击修改数据
来源:互联网 发布:淘宝如何做买家秀 编辑:程序博客网 时间:2024/04/28 21:51
网上关于在CListCtrl控件里面点击直接修改值的东西比较少,其实是个很简单的东西,知识不太容易想到!在这里将代码写下!
void CAdminDialog::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
Invalidate();
HWND hWnd1 = ::GetDlgItem(m_hWnd,IDC_LIST1);
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
RECT rect;
//get the row number
nItem = temp->iItem;
//get the column number
nSubItem = temp->iSubItem;
if(nSubItem == 0 || nSubItem == -1 || nItem == -1)
return ;
//Retrieve the text of the selected subItem from the list
str1 = GetItemText(hWnd1,nItem ,nSubItem);
RECT rect1,rect2;
// this macro is used to retrieve the Rectanle of the selected SubItem
ListView_GetSubItemRect(hWnd1,temp->iItem,temp->iSubItem,LVIR_BOUNDS,&rect);
//Get the Rectange of the listControl
::GetWindowRect(temp->hdr.hwndFrom,&rect1);
//Get the Rectange of the Dialog
::GetWindowRect(m_hWnd,&rect2);
int x=rect1.left-rect2.left;
int y=rect1.top-rect2.top;
if(nItem != -1)
::SetWindowPos(::GetDlgItem(m_hWnd,IDC_EDIT1),HWND_TOP,rect.left + x,rect.top + y,rect.right-rect.left,rect.bottom-rect.top,NULL);
//GetDlgItem(IDC_EDIT1)->SetWindowText(str1);//°ÑEditµÄ¿Ø¼þÖµÉèΪCListCtrlÀïÃæµÄÖµ
m_List.SetItemText(nItem,nSubItem,"");//½«CListCtrlÀïÃæµÃÖµÉèÖóɲ»¿É¼ûµÄ
::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_SHOW);
::SetFocus(::GetDlgItem(m_hWnd,IDC_EDIT1));
//Draw a Rectangle around the SubItem
::Rectangle(::GetDC(temp->hdr.hwndFrom),rect.left + x,rect.top,rect.right,rect.bottom);
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);//µÃµ½Ð޸ĺóµÄÖµ£¬ÒÔ·½±ãÈ·¶¨Ð޸ĺ󽫴ËÖµÖ±½Óдµ½CListCtrlÉÏ
//Set the listItem text in the EditBox
//::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),str1);
*pResult = 0;
}
CString CAdminDialog::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 CAdminDialog::OnChange()
{
// TODO: Add your control notification handler code here
//::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),str1);
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);//µÃµ½EditÀïÃæµÄÄÚÈÝ
m_List.SetItemText(nItem,nSubItem,str1);//½«EditÀïÃæµÄֵдµ½CListCtrl¿Ø¼þÀïÃæÈ¥
//delete GetDlgItem(IDC_EDIT1);
GetDlgItem(IDC_EDIT1)->SetWindowText("");//Òª½«EditµÄÎı¾ÉèÖóɿգ¬²»È»ÔÙ´ÎÏÔʾEditµÄʱºò»áÒ²ÏÔʾÉÏ´ÎÐ޸ĵÄÖµ
GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);//ÒªÒþ²Ø£¬²»ÒªÉ¾³ý£¬ÒòΪɾ³ýÒÑÓÐÔٴε¥»÷µÄʱºò¾Í»á³ö´í
}
- vc中CListCtrl控件点击修改数据
- 【转帖】VC中使CListCTrl控件排序
- VC/MFC中 CListCtrl控件的使用方法
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- CListCtrl 控件VC
- VC的CListCtrl控件
- VC的CListCtrl控件
- vc++ MFC-CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- VC的CListCtrl控件
- 直方图与直方图绘制
- JAVA 编程思想 第4版 学习笔记 - 第五章
- 2个月来一直在看计算几何的东西,
- 在 IIS6.0 中配置 Python3.0 Web 运行环境
- 使用Handy Backup 6.2进行数据备份与还原(多图)
- vc中CListCtrl控件点击修改数据
- Google 盲人科学家推出盲人手机软件
- voa
- swing 绝对布局的使用
- S3C2410快速启动的实现-摘录
- 读zac老哥《网络营销实战密码》一章有感
- RSA加密算法
- 经济危机与互联网双阴影下的IT出版之三
- EB的显色原理