Thread: Listview with c/c++

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    Listview with c/c++

    Im trying to make a listview like the 1 below:

    http://www.c-sharpcorner.com/1/ListViewInCSharp.asp

    The code they provide is in C# and im trying to do it in C/C++, i managed to create the control, but i have a few questions:

    1) The author of the above link says:

    Also, you can now, set the ListView to select an entire row in report mode, something that in Visual C++ you had to write a whole custom ListView control to do.
    Is this true? i dont understand why you cant select an entire row in C/C++...

    2) He also says, notice the nice grid lines, how can i add grid lines to the control i have created, do i need to create it with some sort of WM_EX_GRIDLINES style or something like that? Or would i need to subclass the control and handle the painting?

    3) Ive looking through the entire documentation for listview controls and i cant seem to find anything that returns the column count.. I googled it and all i get is examples in C#

    Anyway, all help would be appreciated.. And if possible, im trying to do this without MFC..

    Thanks in advance

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> 1)...
    LVS_EX_FULLROWSELECT style was added in version 4.7 of Comctl32.dll

    >> 2)...
    LVS_EX_GRIDLINES

    >> 3)...
    I don't see anything at first glance, but since you add the columns you should know how many there are.

    gg

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    thanks for the quick reply codeplug, ill keep looking for how to find the column count though.. the thing is, my listview control has a dynamic number of columns, and it might get a bit confusing trying to keep track of it, and since there is a way to get item count i figured there must be a way to find column count..

    anyway, ill try out LVS_EX_FULLROWSELECT and LVS_EX_GRIDLINES

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I havn't ever seen a way to count columns either. Maybe if you try searching for a way to count subitems.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    that might work, but theres no way to count subitems either (not that i know of anyway), ill just try looping for a large value.. say 99 to 0, calling LVM_GETCOLUMN until i get true

    also, how would i add sorting by column? do i have to add it manually, ie. check for a click on the column header and then sort the items myself? or is there a style i can use?

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    i have 1 last question:

    how can i find out the index of the currently selected item? would i use the LB_ message? or is there an LVM_ message i should use instead..

    thanks in advance

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    List View Controls
    Use the TOC pane on the left to navigate to "List-View Controls Reference" which lists all the macros, messages, notifications, etc... supported.

    For example, the ListView_GetNextItem() macro can be used to find the selected item by using the LVNI_SELECTED flag.

    gg

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    In MFC you can count columns with...

    Code:
    CHeaderCtrl     *pHeader;
    pHeaderCtrl = GetHeaderCtrl();
    if(pHeaderCtrl)
    	iCols = pHeaderCtrl->GetItemCount();
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Which translates into Header_GetItemCount(ListView_GetHeader(hwndLV));

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListView Refresh, Update
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2006, 09:13 AM
  2. Replies: 6
    Last Post: 07-10-2006, 12:05 AM
  3. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 01:26 AM
  4. Edit control on listview
    By knutso in forum Windows Programming
    Replies: 5
    Last Post: 08-10-2003, 09:11 PM
  5. Listview??
    By SuperNewbie in forum C# Programming
    Replies: 4
    Last Post: 02-13-2003, 03:34 AM