Solved Adding Bitmap Button to ListView

Hello,
0_1548235493229_Capture.PNG
I have created this listview (I found it easier than a treeview and it makes what I need) but instead of having checkbox using(LV_COLUMN_CHECKBOX) or buttons (LV_COLUMN_BUTTON) I would like to have bitmap button. I saw that there was LV_COLUMN_BMP for bitmap but I do not know if that will help me and how.
Is there any way I can use something like a bitmap button where I can use icons or images on it for this case.
I would really appreciate if you would offer me an example if such a thing can be done.
Thank you in advance.

Hi @Ogers LV_COLUMN_BMP accept an icon id. You can also register your own icon (meaning you own bitmap) with RegisterIcon from the Icon Librabry.

Note a ListView offer limited support if you want to directly draw into cells you will need to switch to a TreeView.

Here an example for handling LV_COLUMN_BMP .

#include "customgui_listview2.h"

class ListViewDialog : public GeDialog
{
private:
	SimpleListView			listview;
	Int32 GADGET_LISTVIEW = 10001;

public:

	virtual Bool CreateLayout();
	virtual Bool InitValues();
	virtual Bool Command(Int32 id, const BaseContainer& msg);

};

Bool ListViewDialog::CreateLayout()
{
	// first call the parent instance
	Bool res = GeDialog::CreateLayout();

	// Create the LisTView
	AddListView(GADGET_LISTVIEW, BFH_SCALEFIT | BFV_SCALEFIT, 0, 0);
	listview.AttachListView(this, GADGET_LISTVIEW);

	return res;
}

Bool ListViewDialog::InitValues()
{
	// first call the parent instance
	if (!GeDialog::InitValues())
		return false;

	// Define our Columns
	BaseContainer layout = BaseContainer();
	layout.SetInt32('chck', LV_COLUMN_CHECKBOX);
	layout.SetInt32('name', LV_COLUMN_TEXT);
	layout.SetInt32('bttn', LV_COLUMN_BUTTON);
	layout.SetInt32('bmp', LV_COLUMN_BMP);
	listview.SetLayout(4, layout);

	// Fill our columns with 2 Entry
	BaseContainer data = BaseContainer();
	for (Int32 i = 0; i < 2; i++)
	{
		data.SetInt32('chck', true);
		data.SetString('name', "Something"_s);
		data.SetString('bttn', "..."_s);
		data.SetInt32('bmp', IDM_KEY_LAST);
		listview.SetItem(i, data);
	}

	// Update the listView
	listview.DataChanged();

	return true;
}

Bool ListViewDialog::Command(Int32 id, const BaseContainer& msg)
{
	// If there is an action on our ListView
	if (id == GADGET_LISTVIEW)
	{
		// Check the column, if it's an action on the int(bmp) column ID
		Int32 ColId = msg.GetInt32(LV_SIMPLE_COL_ID);
		if(ColId == 'bmp')
		{
			// Retrieves all data of this lines
			Int32 itemId = msg.GetInt32(LV_SIMPLE_ITEM_ID);
			BaseContainer bc;
			listview.GetItem(itemId, &bc);

			// Get the current data of our int(bmp) column / BaseContainer
			Int32 currIconId = bc.GetInt32('bmp');
			switch(currIconId)
			{
				case IDM_KEY_LAST:
					bc.SetInt32('bmp', Osphere);
					break;
				case Osphere:
					bc.SetInt32('bmp', IDM_KEY_LAST);
					break;
				default:
					bc.SetInt32('bmp', IDM_KEY_LAST);
					break;
			}

			// Push back our change to the item
			listview.SetItem(itemId, bc);

			// Update the ListView
			listview.DataChanged();
		}
	}
	return true;
}

If you have any question left, please let me know.
Cheers,
Maxime.

Hello @m_adam
Thank you for your answer. I was looking more to have a bitmap button on my listView instead of just an icon, like a toggle button where the icon is changed when clicked. I have done it but not inside a listView. Is that possible to be done inside the listView.
Thank you.

@ogers said in Adding Bitmap Button to ListView:

like a toggle button where the icon is changed when clicked

It's exactly what the code I posted does. Take a look at the Command method.

Thank you @m_adam
It works fine