[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

CListCtrl problem

Posted on 1999-10-27
4
Medium Priority
?
906 Views
Last Modified: 2013-11-20
I've created a MFC doc-view project which uses the CListView class. I'm using the CListView (and the underlying CListCtrl in effect) in Report View mode. I have added 3 columns to the CListCtrl using the following code :

CListCtrl &pList = GetListCtrl();
int width;

AfxGetMainWnd()->GetClientRect(&rect);
width = (rect.bottom - rect.top) /3;
if ((pList.InsertColumn(0,"SourceName", LVCFMT_LEFT,width)) == -1)
   AfxMessageBox("Could not insert column 0");
if ((pList.InsertColumn(1,"Computer Name",LVCFMT_LEFT,width,0)) == -1)
   AfxMessageBox("Could not insert column 1");
if ((pList.InsertColumn(2,"Event Type",LVCFMT_LEFT,width,1)) == -1)
   AfxMessageBox("Could not insert column 2");

After doing this I'm trying to insert items using InsertItem as follows :

for(countofitems = 0; countofitems < 3; countofitems++) {
item.mask = LVIF_TEXT;
item.iItem = countofitems;
if (countofitems == 0) {
   item.pszText = SourceName;
   item.iSubItem = 0;
} else if (countofitems == 1) {
   item.pszText = ComputerName;
   item.iSubItem = countofitems + 1;
} else if (countofitems == 2) {
   item.pszText = buf.GetBufferbuf.GetLength());
item.iSubItem = countofitems + 1;
}
pList.InsertItem(&item);
}

However, only the first column's data gets inserted (and is seen) not the next two (ie ComputerName and the variable buf).

Any pointers ?
fstab.
0
Comment
Question by:fstab
4 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 2163937
You should use CListCtrl::InsertItem to insert the main items and use CListCtrl::SetItemText to set the text of the subitems. CListCtrl::InsertItem cannot insert subitems.
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2164790
???? width=(rect.bottom - rect.top)/3;

I think it should be:
width = (rect.right - rect.left)/3;
0
 
LVL 1

Expert Comment

by:MFC123
ID: 2167667
Ensure the following order for item structure

fofirst row first column

item.iitem = 0; item.isubitem = 0;
insertitem

for  first row second column
item.iitem = 0; item.isubitem = 1;
setitem

for  first row second column
item.iitem = 0; item.isubitem = 2;
setitem






0
 
LVL 1

Author Comment

by:fstab
ID: 2169518
Thanks to all who responded. However, may I mention that I was also getting some other problems.

I noticed that though I used SetItemText, not all the subitems were getting set to the text I specified, and were random in nature.

I later discovered that this malady (correct me if I'm wrong anyone) was due to my setting the styles to :

cs.style |= LVS_REPORT | LVS_SINGLESEL | LVS_SORTASCENDING;

Don't see it ? Its due to the LVS_SORTASCENDING being set .. On removing this, all subitems were seen.

Thanks all again - esp. VBapat for telling me that teeny-weeny bit about the right - left !
fstab.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

590 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