Adding data to random column in List View

This is a discussion on Adding data to random column in List View within the Windows Programming forums, part of the Platform Specific Boards category; Hi My situation is like this: I have one List view in report mode. I know how to create columns ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    87

    Adding data to random column in List View

    Hi

    My situation is like this:
    I have one List view in report mode. I know how to create columns and how to put data in the first column, but what about the other columns?

    I'll appreciate any suggestion. Thank you in advance.

    P.S. I'm programming in pure Win 32 API with C++.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Send an LVM_SETITEM message to the listview control where the iSubItem member of the LVITEM struct is the column number.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    And I thought so, but may be I'm missing something...
    Code:
    		lv_clmn.mask=LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
    		lv_clmn.fmt=LVCFMT_CENTER;
    		lv_clmn.pszText="Column 2";
    		lv_clmn.cx=90;
    		SendMessage(lv,LVM_INSERTCOLUMN,0,(long) &lv_clmn);
    		lv_clmn.mask=LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
    		lv_clmn.fmt=LVCFMT_CENTER;
    		lv_clmn.pszText="Column 1";
    		lv_clmn.cx=90;
    		SendMessage(lv,LVM_INSERTCOLUMN,0,(long) &lv_clmn);
    
    		lv_item.mask=LVIF_TEXT;
    		lv_item.iItem=0;
    		lv_item.iSubItem=0;
    		lv_item.iImage=0;
    		lv_item.pszText="text in column 1";
    		res=SendMessage(lv,LVM_INSERTITEM,0,(long) &lv_item);
    
    		lv_item.mask=LVIF_TEXT;
    		lv_item.iImage=0;
    		lv_item.iItem=0;
    		lv_item.iSubItem=1;
    		lv_item.pszText="sub-item";
    		res=SendMessage(lv,LVM_INSERTITEM,0,(long) &lv_item);
    I don't know why, but only the first message works.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    When you use SendMessage to insert columns with LVM_INSERTCOLUMN, set the wParam to the column number, ie.
    Code:
    SendMessage(lv,LVM_INSERTCOLUMN,0,(long) &lv_clmn);
    /*stuff*/
    SendMessage(lv,LVM_INSERTCOLUMN,1,(long) &lv_clmn);
    /*stuff*/
    SendMessage(lv,LVM_INSERTCOLUMN,2,(long) &lv_clmn);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    "I don't know why, but only the first message works."

    I mean that only the first LVM_INSERTITEM message works. I
    succesfully create the columns with the first two messages.
    But I can't put anything in the second column with the 4th message:
    Code:
    res=SendMessage(lv,LVM_INSERTITEM,0,(long) &lv_item);
    Can you see where is my mistake?

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try using LVM_SETITEM, as I originally suggested, instead of LVM_INSERTITEM, ie.
    Code:
    lv_item.mask=LVIF_TEXT;
    lv_item.iImage=0;
    lv_item.iItem=0;
    lv_item.iSubItem=1;
    lv_item.pszText="sub-item";
    res=SendMessage(lv,LVM_SETITEM,0,(long) &lv_item);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    Thank you. This works fine for me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. List View troubles (adding items)
    By scwizzo in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2008, 04:09 PM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Link to outside data in list view
    By eth0 in forum Windows Programming
    Replies: 5
    Last Post: 01-13-2006, 04:08 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. List View column
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 07-10-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21