Solved

ListView_InsertColumn returning -1

Posted on 1998-04-23
9
639 Views
Last Modified: 2013-12-03
What can possibly be the cause of that? Note that it only happens on some computers, on most of them it works no problem. Here's the code:

void CreateListView(HWND hWnd)
{
      LV_COLUMN item;
      int i;
      char *cpitem[] = {"Date", "To", "Subject", "Address", "From"};
      
      InitCommonControls();

      if ((list = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
            WS_VISIBLE | WS_CHILD | LVS_ALIGNLEFT | LVS_REPORT,
            0, 0, 0, 0, hWnd, (HMENU)55, hInst,
            NULL)) == NULL)
            return;
      
      item.mask      = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
      item.fmt      = LVCFMT_LEFT;
      item.cx            = WIDTH / ((sizeof cpitem / sizeof cpitem[0]) + 1);
      for (i = 0; i < sizeof cpitem / sizeof cpitem[0]; ++i)
      {
            item.pszText = cpitem[i];
            item.cchTextMax = strlen(cpitem[i]);
            if (ListView_InsertColumn(list, 0, &item) == -1)
                  MessageBox(hWnd, "Failed to create column", appname, MB_OK);
      }
}
0
Comment
Question by:_Zaphod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1396992
Could you sent a piece od code
0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396993
Edited text of question
0
 
LVL 23

Expert Comment

by:chensu
ID: 1396994
It seems that ListView_InsertColumn(list, 0, &item) should be ListView_InsertColumn(list, i, &item);
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Author Comment

by:_Zaphod
ID: 1396995
That's not true, I want the columns to be in the opposite order than that in which I wrote the char*[]. The reason for that is that I was stupid first and lazy later :)
And besides, that's no reason for it to fail (I always thought).
0
 

Expert Comment

by:RLM
ID: 1396996
Try including LVCF_SUBITEM in item.mask and set item.iSubItem to 0 before calling.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1396997
1) Reset all members of the item before the call:
  LV_COLUMN item = { 0 };

2) Use GetLastError() for a possible explanation.

0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396998
*shrug* Didn't work.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1396999
What did GetLastError() return?  (see WINERR.H for a translation of the error codes).

This way:

    if (ListView_InsertColumn(list, 0, &item) == -1)
    {
        int err = GetLastError();
        // ...
    }
0
 

Accepted Solution

by:
RLM earned 50 total points
ID: 1397000
Take 45 from dresser. Load. Point at computer. Pull trigger.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question