Double-click ListControl to implement editable

Source: Internet
Author: User

On_policy processes listControl messages

The message ing of the list control also uses the ON_NOTIFY macro in the form of ON_NOTIFY (wyycode, id, memberFxn). wNotifyCode is the notification code and id is the window ID that generates the message, memberFxn is a processing function. The prototype of the function is like void OnXXXList (NMHDR * pNMHDR, LRESULT * pResult). pNMHDR is a data structure and needs to be converted to other types of structures during use. The values of the list control and the corresponding data structure are as follows:

· LVN _ BEGINLABELEDIT is sent when a character is edited. The structure used is NMLVDISPINFO.

· LVN _ ENDLABELEDIT is sent when an edit character is completed. The structure used is NMLVDISPINFO.

· LVN _ GETDISPINFO is sent when you need to obtain certain information (for example, to obtain the display characters of a certain item). The structure used is NMLVDISPINFO.

================ Repost the above theory, the application example is as follows ========================

Example: Double-click list item to rename an item

// In_message_map (CPage, CDialog) ON_NOTIFY (NM_DBLCLK, IDC_LIST, & CPage: Success) ON_NOTIFY (success, IDC_LIST, & CPage :: onLvnEndlabeleditList) END_MESSAGE_MAP () implements void CPage: OnNMDblclkList (NMHDR * pNMHDR, LRESULT * pResult) {// double-click the event to generate the edit Control, editLabel first determines whether the list is setFocus * pResult = 0; POSITION Pos = counter (); int tIndex = m_List_Tip.GetNextSelectedItem (pos); if (tIndex> = 0) {m_List_Tip.SetFocus (); CEdit * pEdit = m_List_Tip.EditLabel (tIndex );}} invalid void CTipTrapPage: OnLvnEndlabeleditListTip (NMHDR * pNMHDR, LRESULT * pResult) {// edit the end event parameter NMHDR * pNMHDR forcibly converted to the corresponding structure NMLVDISPINFO // you can get the current list NMLVDISPINFO * pDispInfo = reinterpret_cast <NMLVDISPINFO *> (pNMHDR); * pResult = 0; CString pName = pDispInfo-> item. pszText; int tIndex = pDispInfo-> item. iItem; m_List.SetFocus (); if ((! PName. IsEmpty () & tIndex> = 0) {m_List.SetItemText (tIndex, 0, pName );}}

 

Finally, do not forget to hook up the property: list Control-> property-> Styles-> Edit labels;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.