add button to listview

This is a discussion on add button to listview within the Windows Programming forums, part of the Platform Specific Boards category; Is it possible to add a button in a column of a listview control ? I want the user to ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    13

    add button to listview

    Is it possible to add a button in a column of a listview control ?

    I want the user to be able to click on a button for each row in the listview control. I know checkboxes are possible, but I would rather have a button if possible.

    I am programming in C (lean and mean)

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Yes you can create any type of control within another (mostly...)

    I use edits and combos all the time.



    A check box will look like a button if give the style BS_PUSHLIKE
    "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

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    13
    Thanks for the reply, Any code snippets you can share ?

    I am using the following code to add a column:

    lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
    lvc.fmt = LVCFMT_LEFT;
    lvc.iSubItem = 2;
    lvc.cx = 150;
    lvc.pszText = TEXT("Set Name");
    ListView_InsertColumn(hListView, 2, &lvc);

    I saw an example once that said it put a radio button in the first column but when I compiled the code it left that column blank, and now I cannot find that snippet to even show you what I was looking at

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    this will add a checkbox to the first column.

    It will also draw grid lines and highlight the full row the user selects. I find these styles make the listview easier to use (and looks more like an Excel sheet).

    Code:
    	
    DWORD exStyles = LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES| LVS_EX_CHECKBOXES;
    ListView_SetExtendedListViewStyle(hWndListView, exStyles);
    On closer inspection it appears that you would have to do some major work to change the checkbox style. In some versions the checkbox is two images, one for unchecked and one for checked.

    You can create your own button (CreateWindow) the size of the cell and set the listview as its parent.
    This requires you to do alot of background work (ie resizes) and I would suggest waiting until you are more comfortable with WIN32 before attempting it.

    ListView_GetCheckState()
    ListView_SetCheckState()
    "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

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    13
    I had actually just found the extended listview styles yesterday and have now opted to just use LVS_EX_FULLROWSELECT and abandon the buttons altogether. I like the gridlines feature, which tidied it all up quite a bit.

    Once I figured out some changes in my initial code

    #define _WIN32_IE 0x0400
    #include <Shellapi.h>

    needed to be added to use the extended styles in GNU GCC since I had defined WIN32_LEAN_AND_MEAN.

    I'ts been a while since I wrote any software for Windows (I'm just an old school ansi C programmer)

    Thank you very much for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 07:53 AM
  2. ListView Version 6.0 and ImageLists
    By blundstrom in forum Windows Programming
    Replies: 0
    Last Post: 07-26-2002, 09:35 AM
  3. disabling button in another prog
    By timmygax in forum Windows Programming
    Replies: 11
    Last Post: 10-29-2001, 02:40 PM
  4. Button Identifier Problems!
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 05:48 PM
  5. Unselecting a selected button in C++Builder 5
    By Frozen_solid in forum Windows Programming
    Replies: 4
    Last Post: 09-25-2001, 07:57 PM

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