Edit control on listview

This is a discussion on Edit control on listview within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to edit items/subitems in a listview by creating an edit control when the user doubleclicks a subitem. I've ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Edit control on listview

    I'm trying to edit items/subitems in a listview by creating an edit control when the user doubleclicks a subitem.
    I've managed to do this, but i'm having some trouble with events from the editctrl..
    When i set the dialog as the parent, the hottracking from the listview makes the item repaint, thus making the edit invisible.
    I tried to solve this by setting the listview as the editctrl's parent, but now the editctrl doesn't send EN_KILLFOCUS messages anymore.
    Is there a way i can disable the repainting of the area behind the editctrl? I think that would be the easiest solution..?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Does your listview have the LVS_EDITLABELS style ie are you using the default listview label editing capability?

    >>Is there a way i can disable the repainting of the area behind the editctrl?<<

    If your're not using the default editing facility of listviews, then you may want to try either InvalidateRect or RedrawWindow on the edit control after the listview has done its thing. You may also attempt to use ValidateRect on the listview/parent window itself using the edit's dimensions but I think this would probably fail.

    >>but now the editctrl doesn't send EN_KILLFOCUS messages anymore.<<

    It probably is but, since they are sent as WM_COMMAND's to the parent (ie your listview), you'd probably need to subclass the listview to get at them.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I do the same thing to enable an editable subitems in Listviews.
    The Listview, as Ken said, must have the LVS_EDITLABELS and LVS_REPORT styles.

    I set a new WndProc (callback function) for the LV and look for the WM_LBUTTONDOWN msg's. Get and SetWindowLong() or SetWindowLongPtr(). I have posted examples.

    I use ListView_SubItemHitTest() to find the item, subitem clicked on.
    Then I create an edit the same size as that cells client rect (ListView_GetSubItemRect() ).
    Any msg's I don't want to respond to I send back to the original WndProc with CallWindowProc()

    I then set the edits WndProc to one I have written.
    The edit must have ES_WANTRETURN | ES_MULTILINE to get the return key.
    When the edit is finished I sent the dialog a LVN_ENDLABELEDIT msg filling in a LV_DISPINFO struct holding the item ,subitem and text.

    I respond o the LVN_ENDLABELEDIT by setting subitems text.

    So I have the dlg's wndproc, the LV's WndProc and the Edits WndProc......but I don't have a paint problem.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I've set the listview to LVS_LABELEDIT, but i don't receive any LVN_BEGINLABELEDIT message when i click the listview..
    The code below is working, except for that i have to disable the listview when editing a subitem..
    If i can get the LVS_LABELEDIT parameter to work, will the listview create the edit box and all the handling, so i only have to receive the infostruct in the LVN_BEGINLABELEDIT/LVN_ENDLABELEDIT message?

    Code:
    	case WM_NOTIFY:	// Process messages from listview
    		switch(((LPNMHDR)lParam)->code){
    		case NM_DBLCLK:
    			if(((NMLISTVIEW*)lParam)->iSubItem && ((NMLISTVIEW*)lParam)->iItem>=0 && iCol==0){
    				ListView_GetSubItemRect(hwLst, ((NMLISTVIEW*)lParam)->iItem, ((NMLISTVIEW*)lParam)->iSubItem, LVIR_LABEL, &r1);
    				iCol = ((NMLISTVIEW*)lParam)->iSubItem;
    				GetLstItem(hwLst, achBuf, 300, ((NMLISTVIEW*)lParam)->iItem, ((NMLISTVIEW*)lParam)->iSubItem);
    				hwEdit = CreateWindowEx(WS_EX_CLIENTEDGE|WS_EX_TOPMOST|WS_EX_TRANSPARENT, "EDIT", achBuf, WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL, r1.left+3, r1.top+1, r1.right-r1.left+3, r1.bottom-r1.top+5, hwThis, (HMENU)TXT_EDIT, *pInst, 0);
    				SetFont(GetDlgItem(hwThis, TXT_EDIT), 8, "Ms Sans Serif");
    				ShowWindow(GetDlgItem(hwThis, TXT_EDIT), SW_SHOW);
    				EnableWindow(hwLst, 0);
    				wpr = (WNDPROC)SetWindowLong(GetDlgItem(hwThis, TXT_EDIT), GWL_WNDPROC, (long)SubProc);
    				SetFocus(GetDlgItem(hwThis, TXT_EDIT));
    			}
    			break;
    		case LVN_BEGINLABELEDIT:
    			b("LVN_BEGINLABELEDIT");
    			break;
    		case LVN_ENDLABELEDIT:
    			b("LVN_ENDLABELEDIT");
    			break;
    		}
    		break;
    (The b() function displays a messagebox)

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    OK, i found the ListView_EditLabel() function. But this function only allows me to edit the first item, so I'm back to creating an editbox again...

    I then have two problems:
    1. How to detect scrolling of the listview. What message do i have to intercept?
    2. I want to have the listview enabled during subitem edit. This doesn't work; whenever i move the mouse over the edit, the edit is erased by the listviews repaint, and if i click somewhere in the text of the edit, the edit loses focus, and is destroyed.

    If you have seen earlier posts from me, you might have noticed that i'm not too familiar with painting/drawing functions..
    How do i control the painting of the listview/editbox? Do i have to subclass both, and process the WM_PAINT message?
    Any examples?

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    As you have discovered you can only edit the first item in standard Listviews.

    I do not do any paint handling for the edit, listview or dlg.

    I have subclassed the ListView and the edit.

    If the edit looses focus then the edit is destroyed and I send the Listview a LVN_ENDLABLEEDIT msg. ( I set the LV_DISPINFO to hold the new text.) I do not use the LVN_BEGINLABELEDIT msg.

    I ensure that the item I am editing (and all others) in the LV is deselected as soon as the edit is created.

    Your problem may be with the transparent style. This style will cause the LV to be repainted as the edit changes.

    You also need to add the ES_WANTRETURN and ES_MULTILINE. These two styles are needed or your edit will not get msg's (do what you want) when the RETURN key is pressed.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. edit control text buffer
    By scurvydog in forum Windows Programming
    Replies: 4
    Last Post: 12-11-2008, 10:13 AM
  2. Edit control template
    By BobS0327 in forum Windows Programming
    Replies: 3
    Last Post: 04-08-2005, 01:10 PM
  3. How can I send a text string to an edit control
    By marc74 in forum Windows Programming
    Replies: 5
    Last Post: 01-06-2005, 10:14 PM
  4. endless edit control
    By ZerOrDie in forum Windows Programming
    Replies: 3
    Last Post: 03-21-2003, 02:51 AM
  5. Keeping focus on an edit control ...
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 02-19-2002, 02:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21