?
Solved

CListCtrl + Rename

Posted on 1998-08-27
9
Medium Priority
?
1,127 Views
Last Modified: 2013-11-19
Hi!
I am building an "Organize Bookmarks" dialog and I am
using a CListCtrl.
When clicking twice (or by pressing F2) the user can
rename an item in the list.
My problem is that I want a Button (rename) on the dialog
to perform the same action as for example pressing F2
on an item. My MFC knowledge isn't that good so if
someone could tell me how to do this I would really
appreciate it!

Best rgds // Anders
0
Comment
Question by:Kalle 2
9 Comments
 
LVL 1

Expert Comment

by:motigust
ID: 1321350
1. Write a function "OnRename" that finds the selected item and renames it.

2. Call "OnRename" at the OnKeyDown Function when the user presses F12

3. Call that function again from the message of Clicking the button.

(In Order to do that, use the wizard to generate a function for the BN_CLICKED message of the button)

0
 

Author Comment

by:Kalle 2
ID: 1321351
I think I was a bit unclear. I would like my Rename-button
to do the same as the Rename-button in IE4 Explorer "Organize Favorites" does.
That is to place the cursor on the selected item in edit-mode.

// Anders
0
 
LVL 7

Expert Comment

by:galkin
ID: 1321352
Use CListCtrl::EditLabel function to edit listview item. Your listview must have LVS_EDITLABELS style.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Kalle 2
ID: 1321353
That would return the handle of an edit-control which I
can use I guess. But how do I use it?

// Anders
0
 
LVL 7

Expert Comment

by:galkin
ID: 1321354
Call to EditLabels has the same effect as left clicking on the selected node. It means it creates edit control in node label. This function returns handle to this edit control allowing you to change edit control style, select any text in this edit control etc.
0
 

Author Comment

by:Kalle 2
ID: 1321355
Sorry if I am a bit slow. This is the code I am using to get
hold of the handle to the edit-control. It does not succeed
and I have got LVS_EDITLABELS style enabled. Could you tell
me what I am doing wrong?

void COrganizeBookmarksDlg::OnRename()
{
  CEdit* pEdit;
  CListCtrl* pList = static_cast<CListCtrl*>
             (GetDlgItem(IDC_LIST));
  int iSel = GetSelected();
  pEdit = pList->EditLabel(iSel);
  if (pEdit != NULL)
    {
      pEdit->SetLimitText(200);
    }
}

// Anders
0
 

Author Comment

by:Kalle 2
ID: 1321356
Adjusted points to 200
0
 
LVL 1

Accepted Solution

by:
elf_k earned 800 total points
ID: 1321357
Here is extraction from MFC help:
"The control must have the focus before you send this message to the control. Focus can be set using the SetFocus function"

So your code must be something like:

void COrganizeBookmarksDlg::OnRename()
{
  CListCtrl* pList=(CListCtrl*)GetDlgItem(IDC_LIST);
  int iSel=GetSelected();
  pList->SetFocus();
  CEdit* pEdit=pList->EditLabel(iSel);
  if(pEdit)
  {
      pEdit->SetLimitText(200);
  }
}

0
 

Author Comment

by:Kalle 2
ID: 1321358
Simple as that! Thank you!

// Anders
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question