Solved

CListCtrl + Rename

Posted on 1998-08-27
9
1,082 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now