about ListCtrl::InsertItem()

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
??

tlxtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vinayak KumbarSr Program ManagerCommented:
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
tlxtAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

tlxtAuthor Commented:
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
tlxtAuthor Commented:
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
tlxtAuthor Commented:
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
paselvamCommented:
"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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.