diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c index 68a5515f1a8..419a823ba19 100644 --- a/dlls/comctl32/listview.c +++ b/dlls/comctl32/listview.c @@ -8808,6 +8808,7 @@ static BOOL LISTVIEW_SetItemCount(LISTVIEW_INFO *infoPtr, INT nItems, DWORD dwFl if (infoPtr->dwStyle & LVS_OWNERDATA) { INT nOldCount = infoPtr->nItemCount; + infoPtr->nItemCount = nItems; if (nItems < nOldCount) { @@ -8820,7 +8821,6 @@ static BOOL LISTVIEW_SetItemCount(LISTVIEW_INFO *infoPtr, INT nItems, DWORD dwFl } } - infoPtr->nItemCount = nItems; LISTVIEW_UpdateScroll(infoPtr); /* the flags are valid only in ownerdata report and list modes */ diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c index 2afa44d348c..a6910d2b985 100644 --- a/dlls/comctl32/tests/listview.c +++ b/dlls/comctl32/tests/listview.c @@ -3418,6 +3418,28 @@ static void test_ownerdata(void) style = GetWindowLongPtrA(hwnd, GWL_STYLE); ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n"); DestroyWindow(hwnd); + + /* The focused item is updated after the invalidation */ + hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT); + ok(hwnd != NULL, "failed to create a listview window\n"); + res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 3, 0); + expect(TRUE, res); + + memset(&item, 0, sizeof(item)); + item.stateMask = LVIS_FOCUSED; + item.state = LVIS_FOCUSED; + res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item); + expect(TRUE, res); + + flush_sequences(sequences, NUM_MSG_SEQUENCES); + res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0); + expect(TRUE, res); + ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, + "ownerdata setitemcount", FALSE); + + res = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); + expect(-1, res); + DestroyWindow(hwnd); } static void test_norecompute(void)