Solved

programmatically enable EDITLABLES in listControl

Posted on 1998-09-18
2
508 Views
Last Modified: 2013-11-19
1)  I want to programmatically enable editing of current SELECTED/FOCUSED list item (in CListCntrl). How to do it (with input focus)?

2)  How to enable editing of a specific column within a row (in multi-column list control)?
-----

For example in AppWizrd when you create a list control (in a dialog) you can set a property flag ("Edit lable" check box) in property page.

I want to do it at run time programmatically. I tried the following, but is not working:

Failed method 1:
-------------------------
//begin in-place editing of the newly inserted row
CEdit * pEdit = m_ListCtrl.EditLabel( m_ListCtrl.GetItemCount( )  );
if (NULL != pEdit )
pEdit->SetFocus();

Failed method   2:
------------------------------
//Insert items
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_STATE;
lvi.iItem = m_ListCtrl.GetItemCount( );
lvi.iSubItem = 0;
lvi.iImage = 0;
lvi.stateMask =  LVIS_CUT | LVIS_DROPHILITED | LVIS_FOCUSED | LVIS_SELECTED |  LVS_EDITLABELS | LVS_SHOWSELALWAYS ;
lvi.state = LVIS_FOCUSED | LVIS_SELECTED ;
       
lvi.pszText = "";
//insert this item now!            m_ListCtrl.InsertItem(&lvi);
//make this new item selected/in-focus
m_ListCtrl.SetItemState(m_ListCtrl.GetItemCount( ), LVIS_FOCUSED | LVIS_SELECTED, LVIS_SELECTED);
            UpdateData(FALSE);

//send begin lable edit message
m_ListCtrl.PostMessage(WM_NOTIFY, IDC_LISTCTRL, (LPARAM)&msgHdr);
//or this line!!!!!!!!!!!!!!!! (alternatively)            ::SendMessage(m_ListEmailUserNames.GetSafeHwnd(), LVN_BEGINLABELEDIT, IDC_LISTCTRL,  (LPARAM)&lvi);


0
Comment
Question by:dvenkat
2 Comments
 

Accepted Solution

by:
umarama earned 50 total points
ID: 1322315
GetItemCount will always be one greater than the highest available item-index for the list ctrl !

Using that for item-index, hence, will never address any valid index !

I could edit my item by issuing EditLabel(correct index). In fact, try subclassing the edit control in OnBeginLabelEdit and the editing feature looks slick !

0
 

Author Comment

by:dvenkat
ID: 1322316
Thanks for pointing out error in my program! It works fine now ( with EditLabel(correct index))

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

815 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

10 Experts available now in Live!

Get 1:1 Help Now