Solved

CListCtrl + Rename

Posted on 1998-08-27
9
1,107 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
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.…

717 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