?
Solved

about ListCtrl::InsertItem()

Posted on 1999-12-22
7
Medium Priority
?
299 Views
Last Modified: 2013-11-20
I have used ListCtrl::InsertColumn() to
Insert 2 Item :ID,NAME;

and how can insert item just bellow the
corresponding column??

LIKE THIS : ID     NAME

            1      tony
            2      tom
??

0
Comment
Question by:tlxt
  • 4
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
Vinayak Kumbar earned 80 total points
ID: 2300764
Hi,

list control variable is m_list
for first row and col
m_list.InsertItem(0,"1");
Then to set in the second col
m_list.SetItemText(0,1,"tony");

sim for second row
m_list.InsertItem(1,"2");
Then to set in the second col
m_list.SetItemText(0,1,"tom");

Hope it helps,
VinExpert
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2300785
Hi again,

the general thing can be put as,
when u r inserting a fresh row use
m_list.InsertItem(rownumber,"text");

then for other columns of the same row u can use
m_list.SetItemText(rownumber, colnumber,"text");

And what is m_list?
U have a list control with ID say ID_LIST,
go to class wizard for that class and click on member variables tab, then select ID_LIST, Click add member button, there select control variable of type CListCtrl.

Hope this helps U
VinExpert
0
 

Author Comment

by:tlxt
ID: 2300900
I tryed what u have told me,the ListCtrl's scroll bar is scrolling
means new item has been added,but
no text appeared!!and i change the
text color,also no appear!
why??

 
0
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.

 

Author Comment

by:tlxt
ID: 2300950
I tryed what u have told me,the ListCtrl's scroll bar is scrolling
means new item has been added,but
no text appeared!!and i change the
text color,also no appear!
why??

 
0
 

Author Comment

by:tlxt
ID: 2300957
I tryed what u have told me,the ListCtrl's scroll bar is scrolling
means new item has been added,but
no text appeared!!and i change the
text color,also no appear!
why??

 
0
 

Author Comment

by:tlxt
ID: 2300992
I tryed what u have told me,the ListCtrl's scroll bar is scrolling
means new item has been added,but
no text appeared!!and i change the
text color,also no appear!
why??

 
0
 

Expert Comment

by:paselvam
ID: 2301401
"m_ListCtrl is List control variable"

// Creating two columns
CRect rect;
m_ListCtrl.GetWindowRect(&rect);

m_ListCtrl.InsertColumn(0,"ID", LVCFMT_LEFT,rect.Width() * 1/2, 0);

m_ListCtrl.InsertColumn(1,"Name", LVCFMT_LEFT,rect.Width() * 1/2, 1);
   
// Inserting Row values  
LVITEM lvitem;
int iActualItem;

CString Str1[]={"1","2","3","4","5","6","7","8","9"};
CString Str2[]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};

for(int i = 0; i<9;i++)
 for(int j = 0;j<2;j++)
 {
   lvitem.mask = LVIF_TEXT;
   lvitem.iItem = (j == 0)?
               i : iActualItem;
   lvitem.iSubItem = j;
   lvitem.pszText = (j == 0)?
      Str1[i].GetBuffer(
          Str1[i].GetLength()):
          Str2[i].GetBuffer(
           Str2[i].GetLength());

   lvitem.iImage = 0;
   if (j == 0)
   {
     // Inserting First Column value
     iActualItem =
     m_ListCtrl.InsertItem(&lvitem);
   }
   else
   {
     // Inserting Second column value
     m_ListCtrl.SetItem(&lvitem);
   }

I think this will help you out.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses
Course of the Month3 days, 3 hours left to enroll

598 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