Thread: ListView ordering

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    43

    ListView ordering

    Hi,

    I have a multicolumn ListView control which I have created directly using the CreateWindowEx function. It has the LVS_REPORT style. I use LVM_INSERTITEM to add items and then LVM_SETITEMTEXT to set the individual columns.

    However, LVM_INSERTITEM always adds new entries at the top of the list. Is there any way to get it to add them at the bottom?
    Windows XP Professional SP2, Code::Blocks Studio 1.0rc2, GCC/G++ 3.4.2 (20040916-1), mingw32-make 3.80.0-3, GDB 5.2.1-1, W32API 3.6

    MingW Runtime 3.9, BinUitls 2.15.91 (20040904-1), MingW Utilities 0.3, Tcl/Tk 8.4.1-1

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Make sure you set the iItem member of the LVITEM struct to the required index.

    See also The Old New Thing: Positioned vs. non-positioned listview views.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    do something like this:

    Code:
    int iIndex = 0;
    /* blah blah blah, switch statement case WM_COMMAND */
    case IDM_ADD:
       lvItem.iItem = iIndex;
       /* blah blah blah, send the LVM_INSERTITEM message */
    
       /* if the item was inserted, increment iIndex by 1 */
       ++iIndex;
    
       /* return TRUE, break, whatever */
    case IDM_REMOVE:
       /* remove the item */
    
       /* if the item removed successfully, decrement iIndex by 1 */
       --iIndex;
    
       /* return TRUE, break, whatever */
    thats how I do it, its simple, but it does the trick .
    Last edited by Bleech; 10-16-2006 at 04:00 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 07-10-2006, 12:05 AM
  2. Tab Ordering of GUI Controls
    By cloudy in forum Windows Programming
    Replies: 2
    Last Post: 04-22-2006, 09:13 AM
  3. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 01:26 AM
  4. Listview with c/c++
    By X PaYnE X in forum Windows Programming
    Replies: 8
    Last Post: 03-20-2005, 11:29 PM
  5. Listview??
    By SuperNewbie in forum C# Programming
    Replies: 4
    Last Post: 02-13-2003, 03:34 AM