Adding Items to ListView?

cpp Sweden
  • 15 years ago
    Hi,
    I need some help. I have an application with a ListView in the main window. From the menu I can open a dialog to add items to the listview. But it doesn't work. I get this error when I try to add a item:

    Debug Assertion Failed!

    Program: ...
    File: f:\rtm\vctools\vc7libs\ship\atlmfc\include\afx.cmn.inl
    Line: 148

    When I click on the OK button in the dialog, it takes the text from a edit control, put it in 'CString ItemTxt' and calls the function below:

    void CApplicationView::AddItem(CString ItemTxt)
    {
       // Converts CString to char
                   const size_t newsize = 100;
                   char n_ItemString[newsize];
       strcpy_s(n_ItemString, ItemTxt);

       CListCtrl& ListCtrl = GetListCtrl();

       LV_ITEM lvi;
       
       lvi.mask = LVIF_TEXT;
       lvi.iItem = 0;
       lvi.iSubItem = 0;
       lvi.pszText = n_ItemString;

       ListCtrl.InsertItem(&lvi);
    }

    Does anyone have any idea whats wrong? Please help me!

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou