?
Solved

CListCtrl + Rename

Posted on 1998-08-27
9
Medium Priority
?
1,113 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
[X]
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
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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

764 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