Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CListCtrl Edit SubItem Text

Status
Not open for further replies.

cdraycott

Programmer
May 24, 2001
57
GB
I have a Dialog with a ListView Control on it.
I have enabled editing of Subitems by overriding the OnBeginLabelEdit and OnEndLabelEdit and only allow editing if a subitem is clicked and not the actual item.
Then I subclass the edit control and place the edit control in the correct place over the subitem.
This all works great apart from 2 things in order of priority.

1. When the edit box appears and allows editing of subitem text the actual item text disappears until editing is finished.

2. The subitem original text is still there behind my edit control so it can be seen if the edit control text gets smaller than it was to begin with.

Does anyone know how i can get around theses issues. I am sure that the first is to do with the subclassing and repainting of the CListCtrl.

Thanks to anyone who can help.

Chris
 
In most cases where I've seen examples of this, I think the programmer usually uses a call to SetWindowText() to put the actual subitem's text in the edit control. In reference to number 2, how does the user see the text behind the edit control? Are you using SetWindowPos() to position the edit control? If so, are you using '&wndTop' for the window placement? is the edit control transparent?

BlackDice

 
Thanks for the Reply BlackDice. I think some more clarification is needed.

If text in row one is as follows:


Col1(item) Col2(Subitem1)
ItemText SubItemText

What happens is this. I select the row in the list control. I then click again on the subitem text. This fires the OnBeginLabelEdit Event. If the click was on a subitem i do the following:

HWND hWnd=
(HWND)m_lstSelected.SendMessage(LVM_GETEDITCONTROL,0,0);
ASSERT(hWnd!=NULL);
m_LVEdit.PreSubclassWindow();
VERIFY(m_LVEdit.SubclassWindow(hWnd));

Which basically gets a window handle to the edit control and then subclasses this to my CEdit derived class.

I then set the correct position for the edit control to be over the subitem and then put the text from the subitem into my edit control.

Now as I said this all works great and I can change the text in the edit control and then it gets set back to the subitem in the OnEndLabelEdit Event.

The problem is that when my Edit box appears and allows the change of the subitem text I lose the text from the actual item(in the case above the text ItemText would disappear.
When the editing is finished the text reappears.

I cant work out why this is happening.

Any ideas?
 
BlackDice,

You asked for an answer to this one if i found it.
I could not directly find an answer using the defauly MFC CListCtrl class and this still remains a puzzle to me.

I was however able to solve the issue by deriving my own class from CListCtrl and overriding certain methods:

OnBeginLabelEdit
OnEndLabelEdit
OnLButtonDown

The initiation of the subitem edit is no done from OnLButton down rather than from beginlabeledit. It is this difference that I think has made the difference.

(I still subcklass the edit control to one of my own derived from CEdit.

CDraycott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top