-
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)
-
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
-
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 :(
-
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()
-
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.