Click to See Complete Forum and Search --> : LVN_ENDLABELEDIT problem


scomet1
June 15th, 2004, 02:44 PM
I am trying to add and edit text in a listview control. I get the LVN_BEGINLABELEDIT message and an edit box opens at the correct spot in the listview, however as soon as I type one alphanumeric key the LVN_ENDLABELEDIT message is sent and editing ends. So it seems that the box is losing focus somehow - could it be the keys presses cause this?

Thanks for any help -
sean

kirants
June 15th, 2004, 03:07 PM
Are you trapping the BEGINLABELEDIT and returning FALSE ?

scomet1
June 15th, 2004, 04:09 PM
Yes, I return FALSE - I saw that problem on someones tutorial elsewhere hehe.

Well I'm trying to keep it simple, but I guess I should post my code. Its pretty much a basic skeleton with my notification message handler and a function to place default text in the list view and send a LVN_BEGINLABELEDIT message.


IDC_DIALOG1_LIST1 is the list control in question:)





static LRESULT NotifyHandler(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
NM_LISTVIEW *pNm;
NMLVKEYDOWN *kd;
NMLVDISPINFO *pdi;
HWND hwndEdit;
HWND hwndList;


switch (wParam) {
case IDC_DIALOG1_LIST1:
pNm = (NM_LISTVIEW *) lParam;
switch (pNm->hdr.code) {

case LVN_BEGINLABELEDIT:
hwndEdit = ListView_GetEditControl(GetDlgItem(hDlg, IDC_DIALOG1_LIST1));
return FALSE;

case LVN_ENDLABELEDIT:
return FALSE;


case LVN_KEYDOWN:
kd = (NMLVKEYDOWN *) lParam;

// period on keyboard..period on numlocked pad..begin newworkorder
if (kd->wVKey == 0xbe || kd->wVKey == 0x6e)
AddNewInvoice(hDlg, "00000000-00-00");

return FALSE; // return value is ignored

}

}

return FALSE;
}




static int AddNewInvoice(HWND hDlg, char * DefaultName)
{
int Count;
LV_ITEM item;
char Invoice[19];
HWND hwndList;

hwndList = GetDlgItem(hDlg, IDC_DIALOG1_LIST1);

strcpy(Invoice,DefaultName);
Count = ListView_GetItemCount(hwndList);
item.mask = LVIF_TEXT|LVIF_PARAM|LVIF_STATE;
item.state = 0;
item.stateMask = 0;
item.iItem = Count;
item.iSubItem = 0;
item.pszText = Invoice;
item.cchTextMax = sizeof Invoice -1;
item.iImage = 0;
item.lParam = 0;
ListView_InsertItem(hwndList, &item);
ListView_SetItemText(hwndList, Count, 0, Invoice);
ListView_EnsureVisible(hwndList, Count, FALSE);
ListView_SetItemState (hwndList, Count, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
ListView_EditLabel(hwndList, Count);
return Count;
}


As I said before, I get the begin edit message, but then as soon as an alphanumeric key is pressed an end edit message is sent. The arrow keys can be used to position the cursor in the edit box however.

Thanks

kirants
June 15th, 2004, 04:15 PM
Probably you could zip the project and post it ?

scomet1
June 15th, 2004, 05:04 PM
Hello,

Ok I've attached the zipped project. Thank you for your time & interest - sean

kirants
June 15th, 2004, 05:28 PM
WM_COMMAND can come for various reasons. common controls also send WM_COMMAND. So , you need to be careful when you implement this handler.

Have attached a code below. For more details check MSDN for WM_COMMAND. It says that for menus and accelerators, the HIWORD of wParam is 0 and 1. So, you need to consider this.


case WM_COMMAND:
{
if((HIWORD(wParam) == 1 || HIWORD(wParam) == 0 ) &&
(LOWORD(wParam) == IDOK))
{
EndDialog(hDlg, TRUE);
return TRUE;
}
}

scomet1
June 15th, 2004, 06:03 PM
Oh, thank you!!!!!!!!!!!!

You are a wonderful person. I appreciate your help so much.
Take it easy:)

S