Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

CListCtrl + Rename

Posted on 1998-08-27
9
1,097 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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.

861 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