Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hey guys
 
I got a listcontrol element in my MFC-dialog (View->Report).
What I wanted: 2 columns, all rows read out from database
 
I tried:
LVITEM lvItem;
 
m_List.InsertColumn(1, "First Column", 0, 150, 1);   // could be created
m_List.InsertItem(1, "First Row");   // could NOT be created
"InsertItem.." could not be created, so I tried another way...
lvItem.mask = LVIF_TEXT;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
lvItem.pszText = "Row one";
m_List.InsertItem(&lvItem);
 
What am I doing wrong or do I have to add something else?
 

Greetings
Epanjohura
Posted 13-Feb-13 21:00pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Item and column indexes start at 0. If you want to have two columns, you must insert two:
InsertColumn(0, _T("Column 1"), LVCFMT_LEFT, 100, 0);
InsertColumn(1, _T("Column 2"), LVCFMT_LEFT, 100, 1);
Then add items to the list where InsertItem() specifies the main item which is shown in the first column and the additional columns are specified by SetItemText():
InsertItem(0, _T("Item 1-1"));
SetItemText(0, 1, _T("Item 1-2"));
InsertItem(1, _T("Item 2-1"));
SetItemText(1, 1, _T("Item 2-2"));
  Permalink  
Comments
epanjohura at 14-Feb-13 3:29am
   
I tried your solution, but it's the same problem as I had before... the program crashes by the line "setItemText(...)"
Jochen Arndt at 14-Feb-13 3:42am
   
Then there must be something else wrong. At first you can put all calls into VERIFY() macros to see which function fails first (requires debug build):
VERIFY(m_List.InsertColumn(...) >= 0);
VERIFY(m_List.InsertItem(...) >= 0);
VERIFY(m_List.SetItemText(...) != 0);
Ensure also that the control uses the report style:
ASSERT((m_List.GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
Marius Bancila at 14-Feb-13 4:20am
   
You must have the LVS_REPORT style to be able to display multiple columns.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Well, it was such a stupid fault...
 
I tried and tried...finally, I just had to change some properties:
 
Owner Data : False
Owner Draw Fixed : False
 

Greetings
Epanjohura
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100