Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:01:42+00:00 2026-06-09T20:01:42+00:00

I have a ListView control with 4 columns that is initialized in the WM_CREATE

  • 0

I have a ListView control with 4 columns that is initialized in the WM_CREATE proc.

        hListView1 = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_CHILD|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS, 230, 20, 300, 250, hwnd, (HMENU)ID_EDIT1, GetModuleHandle(NULL), NULL);
        ListView_SetExtendedListViewStyle(hListView1, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
            lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
        lvCol.fmt = LVCFMT_LEFT;

        lvCol.iSubItem=0;
        lvCol.cx=30;
        lvCol.pszText="";
        ListView_InsertColumn(hListView1, 0, &lvCol);

        lvCol.iSubItem=1;
        lvCol.cx=150;
        lvCol.pszText="Name";
        ListView_InsertColumn(hListView1, 1, &lvCol);

        lvCol.iSubItem=2;
        lvCol.cx=50;
        lvCol.pszText="Size";
        ListView_InsertColumn(hListView1, 2, &lvCol);

        lvCol.iSubItem=3;
        lvCol.cx=80;
        lvCol.pszText="Modified";
        ListView_InsertColumn(hListView1, 3, &lvCol);

Then i have a function that will insert the items (it works fine until i call deleteallitems)

...
LVITEM lvItem;
j = 0;
while(FindNextFile(hFind,&FindFileData)){
lvItem.iItem = j;
        lvItem.iImage = 1;
        if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
            lvItem.iImage = 0;
        }
        ListView_InsertItem(hListView1, &lvItem);
        ListView_SetItemText(hListView1, j, 1, FindFileData.cFileName);
        ListView_SetItemText(hListView1, j, 2, msg1);
        ListView_SetItemText(hListView1, j, 3, msg2);
        j++;
}

But then whenever i call

ListView_DeleteAllItems(hListView1);

if after i call my function that insert items, my listview is cleared (the columns are still there) but no new items are insered..
I heard about indexes that are not cleared but i couldnt figured it out.

Thanks in advance 😉

Solution :
Added

    lvItem.mask = LVIF_IMAGE | LVIF_STATE;
lvItem.state = 0;
lvItem.stateMask = 0;
lvItem.iSubItem = 0;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:01:43+00:00Added an answer on June 9, 2026 at 8:01 pm

    You are not setting lvItem.mask, so ListView_InsertItem doesn’t know which fields are valid and which aren’t.

    Try something like this:

    ...
    LVITEM lvItem;
    lvItem.mask = LVIF_IMAGE | LVIF_DI_SETITEM;
    j = 0;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView control set up in details mode with 5 columns. It
OK, so, I have a ListView-derived control that changes Grouping and ItemsSource on the
I have a SQLDataSource that is bound to a ListView control but I want
I have a ListView that contains items with four columns. The values in three
I have a System.Windows.Forms.ListView control that I was using with View = View.List .
Okay so I have a listview control with 3 columns: Year | NetTotal |
Couldn't find an answer to this one. I have a WPF ListView control that
I have a custom control that is derived from ListView . This list view
I have a shopping cart ListView control backed by a custom object that has
I have a WPF ListView control for which I am dynamically creating columns. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.