<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to add Check box CheckedIcon and UncheckedIcon in a List Box list items Tab? in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287515#M2204</link>
    <description>Thank you !</description>
    <pubDate>Tue, 27 Jul 2021 10:07:43 GMT</pubDate>
    <dc:creator>Jahidur</dc:creator>
    <dc:date>2021-07-27T10:07:43Z</dc:date>
    <item>
      <title>How to add Check box CheckedIcon and UncheckedIcon in a List Box list items Tab?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287513#M2202</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;I created a List Box with 2 tabs, In the first tab I insert some text in every list item, and in the second tab, i want to add a check box where i can check and uncheck any list items. I use the &lt;STRONG&gt;SetOnTabItem&lt;/STRONG&gt; method to add check box in list items. But the problem is when i select list items the check box gets visible only in that selected list item. But in other list items, the check box gets invisible. That's why i want to add an icon in those unselected list items where an icon will represent is that the list item check box is checked or unchecked. I used the &lt;STRONG&gt;SetTabItemIcon&lt;/STRONG&gt; to do this but can't get an acceptable result. Here i share my code files to understand my approach to do this task.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;My .hpp File&lt;/STRONG&gt;
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;// *****************************************************************************
// Header file for the AttributeList Example Dialog in DG Test Add-On
// API Development Kit 24; Mac/Win
//
// Namespaces:        Contact person:
//     -None-						LT
//
// [SG compatible] - Yes
// *****************************************************************************

#ifndef TESTDIALOG_H
#define TESTDIALOG_H
#pragma once
#include	"DGModule.hpp"

#define ATTRIBUTE_LIST_DIALOG_RESID			32590

// --- AttributeListDialog -----------------------------------------------------

class TestListDialog : public DG::ModalDialog,
	public DG::PanelObserver,
	public DG::ListBoxObserver,
	public DG::ButtonItemObserver,
	public DG::CheckItemObserver,
	public DG::CompoundItemObserver,
	public DG::PopUpObserver
{
private:
	
	TestListDialog* dialog;
	DG::Button					closeButton;
	DG::Button					hiButton;
	DG::TextEdit				EditBox;
	DG::PopUp					popUpBox;
	DG::CheckBox				checkBox;
	DG::SingleSelListBox		ListBox;
	DG::Button					updateButton;

public:

	void	ButtonClicked(const DG::ButtonClickEvent&amp;amp; ev) override;
	void	PanelResized(const DG::PanelResizeEvent&amp;amp; ev) override;
	void	SetTabData(short dialId, short item);
	virtual void	ListBoxSelectionChanged(const DG::ListBoxSelectionEvent&amp;amp; ev) override;
	void TestInitListBox(short dialId);
	


	TestListDialog();
	~TestListDialog();
};

class Data
{
	// Access specifier
public:

	// Data Members
	GS::UniString name;
	short index;

	// Member Functions()
	void printname()
	{
		//Use it if needed !
	}
};

#endif // ATTRIBUTELISTDIALOG_H

&lt;/PRE&gt;
&lt;STRONG&gt;My .cpp File&lt;/STRONG&gt;
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;// *****************************************************************************
// Source code for the AttributeList Example Dialog in DG Test Add-On
// API Development Kit 24; Mac/Win
//
// Namespaces:			Contact person:
//		-None-						LT
//
// [SG compatible] - Yes
// *****************************************************************************

#include	"Test.hpp"

#include	"APIEnvir.h"
#include	"ACAPinc.h"					// also includes APIdefs.h
#include    "APIdefs.h"
//#include	"APICommon.h"
#include "DGModule.hpp"
#include "StringConversion.hpp"
//#include	"UCModule.hpp"
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

#include "RSTypes.hpp"
#include "DGListBox.hpp"

//------------------------------------------ Global Variable ------------------------------------

short listSelected = 0;
std::vector&amp;lt;std::pair&amp;lt;short, short&amp;gt;&amp;gt; dataFiles;
//---------------------------- Class AttributeListDialog -----------------------

enum {
	CloseButtonId = 1,
	hiButtonId = 2,
	EditBoxId = 3,
	popUpBoxID = 4,
	checkBoxID = 5,
	ListBoxId = 6,
	UpdateButtonId = 7
};

enum {
	NameTab = 1,
	ControlTab = 2
};


TestListDialog::TestListDialog() :
	DG::ModalDialog(ACAPI_GetOwnResModule(), 32590, ACAPI_GetOwnResModule()),
	closeButton(GetReference(), CloseButtonId),
	hiButton(GetReference(), hiButtonId),
	EditBox(GetReference(), EditBoxId),
	popUpBox(GetReference(), popUpBoxID),
	checkBox(GetReference(), checkBoxID),
	ListBox(GetReference(), ListBoxId),
	updateButton(GetReference(), UpdateButtonId)
{
	hiButton.Hide();
	EditBox.Hide();
	popUpBox.Hide();
	checkBox.Hide();
	Attach(*this);
	AttachToAllItems(*this);
	TestInitListBox(32590);
	/*addPopUpData(32590, popUpBoxID);*/
}


TestListDialog::~TestListDialog()
{
	DetachFromAllItems(*this);
	Detach(*this);
}



void TestListDialog::SetTabData(short dialId, short item)
{
	DGListTabData lTabData[2];
	API_Rect lBox;

	DGGetItemRect(dialId, item, &amp;amp;lBox.left, &amp;amp;lBox.top, &amp;amp;lBox.right, &amp;amp;lBox.bottom);
	lBox.right -= 10;
	short width = (short)(lBox.right - lBox.left);

	lTabData[0].begPos = 0;
	lTabData[0].endPos = (short)(width);
	lTabData[0].justFlag = DG_IS_LEFT;
	lTabData[0].truncFlag = DG_IS_TRUNCEND;
	lTabData[0].hasSeparator = false;
	lTabData[0].disabled = false;

	lTabData[1].begPos = lTabData[0].endPos;;
	lTabData[1].endPos = (short)(lBox.right);//250;
	lTabData[1].justFlag = DG_IS_LEFT;
	lTabData[1].truncFlag = DG_IS_TRUNCEND;
	lTabData[1].hasSeparator = false;
	lTabData[1].disabled = false;

	DGListSetTabData(dialId, item, 2, &amp;amp;lTabData[0]);
}



void TestListDialog::TestInitListBox(short dialId)
{
	
	//------------------------------------------------------------------------------------( New Try )-----------------------------------------------------

	//SetTabData(dialId, ListBoxId);
	ListBox.SetHeaderSynchronState(false);
	ListBox.SetHeaderItemCount(2);

	ListBox.SetHeaderItemSizeableFlag(NameTab, true);
	ListBox.SetHeaderItemSizeableFlag(ControlTab, true);

	//setting the text of the tab item
	ListBox.SetHeaderItemText(NameTab, "Name");
	ListBox.SetHeaderItemText(ControlTab, "Template");

	//setting the header size of the tab
	ListBox.SetHeaderItemSize(NameTab, 200);
	ListBox.SetHeaderItemSize(ControlTab, 300);

	ListBox.SetHeaderItemSizeableFlag(NameTab, true);
	ListBox.SetHeaderItemSizeableFlag(ControlTab, true);

	ListBox.SetHeaderItemStyle(NameTab, DG::ListBox::DefaultJust, DG::ListBox::EndTruncate);
	ListBox.SetHeaderItemStyle(ControlTab, DG::ListBox::DefaultJust, DG::ListBox::EndTruncate);


	ListBox.SetTabFieldCount(2);

	//setting properties of the tab
	short k = ListBox.GetItemWidth();
	short pos = 0;
	ListBox.SetTabFieldProperties(NameTab, pos, pos + 200, DG::ListBox::Left, DG::ListBox::NoTruncate, false);
	pos += 200;
	ListBox.SetTabFieldProperties(ControlTab, pos, pos + 200, DG::ListBox::Left, DG::ListBox::NoTruncate, false);


	//Create List Box items
	for (short i = 1; i &amp;lt;= 4; i++)
	{
		GS::UniString listItemName = "Test - "+ GS::ValueToUniString(i);
		GS::UniString listItemName2 = "Semple Text No - "+ GS::ValueToUniString(i);
		ListBox.AppendItem();
		ListBox.SetTabItemText(i, NameTab, listItemName);
		ListBox.SetTabItemText(i, ControlTab, listItemName2);
	}

	// -------------------------------------------------- Set the UserData in list items -----------------------------------------------------------------
	//DGListSetItemUserData(short  dialId, short  item, short  listItem, DGUserData   value);

	for (short i = 1; i &amp;lt;= 4; i++)
	{
		Data* obj = new Data();
		obj-&amp;gt;index = i;
		obj-&amp;gt;name = "This is the list item number - " + GS::ValueToUniString(i);
		DGListSetItemUserData(dialId, ListBoxId, i, reinterpret_cast&amp;lt;DGUserData&amp;gt;(obj));
	}
	
	/*short appendedIndex = DGAppendDialogItem(dialId, DG_ITM_CHECKBOX, DG_BT_TEXT, 0, 10, 60, 80, 18);
	DG::Button btn(dialId, appendedIndex);*/
}



void TestListDialog::PanelResized(const DG::PanelResizeEvent&amp;amp; ev)
{
	short hGrow = ev.GetHorizontalChange();
	short vGrow = ev.GetVerticalChange();
	if (hGrow != 0 || vGrow != 0) {
		BeginMoveResizeItems();
		closeButton.MoveAndResize(0, vGrow, hGrow, 0);
		updateButton.MoveAndResize(0, vGrow, hGrow, 0);
		EndMoveResizeItems();
	}

}

void TestListDialog::ListBoxSelectionChanged(const DG::ListBoxSelectionEvent&amp;amp; ev)
{
	
	if (ev.GetSource() == &amp;amp;ListBox)
	{
		short listItemIndex = ListBox.GetSelectedItem();

		//Get the UserData from list items
		//DGListGetItemUserData(short  dialId, short  item, short  listItem);
		short data = DGListGetItemUserData(32590, ListBoxId, 1);
		Data* selectedData = reinterpret_cast&amp;lt;Data*&amp;gt; (DGListGetItemUserData(32590, ListBoxId, listItemIndex));
		GS::UniString dataname = selectedData-&amp;gt;name;
		short selectedIndex = selectedData-&amp;gt;index;

		if (listItemIndex &amp;lt;= ListBox.GetItemCount() &amp;amp;&amp;amp; listItemIndex &amp;gt; 0) {
			if (listItemIndex == 1)
			{
				ListBox.SetOnTabItem(ControlTab, checkBox); //Check Box

				bool ischeck = checkBox.IsChecked();
				const DG::Icon &amp;amp; icon = DG::Icon(ACAPI_GetOwnResModule(), DG::ListBox::SpecialIcons::UncheckedIcon);
				ListBox.SetTabItemIcon(listItemIndex, ControlTab, icon);

			}
			else if (listItemIndex == 2)
			{
				ListBox.SetOnTabItem(ControlTab, checkBox); //Check Box

				bool ischeck = checkBox.IsChecked();
				const DG::Icon &amp;amp; icon = DG::Icon(ACAPI_GetOwnResModule(), DG::ListBox::SpecialIcons::UncheckedIcon);
				ListBox.SetTabItemIcon(listItemIndex, ControlTab, icon);
			}
			else if (listItemIndex == 3)
			{
				ListBox.SetOnTabItem(ControlTab, checkBox); //Check Box

				bool ischeck = checkBox.IsChecked();
				const DG::Icon &amp;amp; icon = DG::Icon(ACAPI_GetOwnResModule(), DG::ListBox::SpecialIcons::UncheckedIcon);
				ListBox.SetTabItemIcon(listItemIndex, ControlTab, icon);
			}
			else if (listItemIndex == 4)
			{
				//Do--------------------------------------------------------------------------------------
				//Do--------------------------------------------------------------------------------------
				ListBox.SetOnTabItem(ControlTab, checkBox); //Check Box
				
				bool ischeck = checkBox.IsChecked();
				const DG::Icon &amp;amp; icon = DG::Icon(ACAPI_GetOwnResModule(), DG::ListBox::SpecialIcons::UncheckedIcon);
				ListBox.SetTabItemIcon(listItemIndex, ControlTab, icon);


				listSelected = listItemIndex;
			}


		}
		//dialog-&amp;gt;ListBox.SetOnTabItem(ControlTab, dialog-&amp;gt;EditBox);
	}
	//dialog-&amp;gt;ListBox.SetOnTabItem(ControlTab, dialog-&amp;gt;EditBox);
}


void	TestListDialog::ButtonClicked(const DG::ButtonClickEvent&amp;amp; ev)
{
	if (ev.GetSource() == &amp;amp;closeButton) {
		dataFiles.clear();
		PostCloseRequest(Accept);
	}
	else if (ev.GetSource() == &amp;amp;hiButton)
	{
		PostCloseRequest(Accept);
	}
	else if (ev.GetSource() == &amp;amp;updateButton)
	{
		//Do
		short k = dataFiles.size();
		short a = 0;
	}

}
&lt;/PRE&gt;
&lt;STRONG&gt; And the .grc Part of this task&lt;/STRONG&gt;
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;/* ---------------------------------------------------------- Demo Dialog */ //-------------------------------------------------------------------------------------------------------

'GDLG'  32590  Modal | grow         0    0  610  350  "Demo Example Dialog" {
/* [  1] */ Button				  400  280  70   24	   LargePlain  "Close"
/* [  2] */ Button				    0    0  100   20	   LargePlain  "Hi!"
/* [  3] */ TextEdit		        0    0  150  20	   LargePlain  40
/* [  4] */ PopupControl	        0    0  150  20	80  3
/* [  5] */ CheckBox				0    0  150  18		SmallPlain "Check Box"
/* [  6] */ SingleSelList		   30   30  500  230	LargePlain  PartialItems  23 HasHeader 25
/* [  7] */ Button				  300  280  70   24	   LargePlain  "Update"
}

'DLGH'  32590  DLG_32590_AttributeList_Example_Dialog {
1	""							Button_0
2	""							Button_1
3	""							TExt_0
4	""							PopupControl_0
5	""							CheckBox_0
6	""							SingleSelList_0
7	""							Button_2
}
&lt;/PRE&gt;
I also share my current status view of this window picture to.&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Sep 2021 07:26:07 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287513#M2202</guid>
      <dc:creator>Jahidur</dc:creator>
      <dc:date>2021-09-14T07:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to add Check box CheckedIcon and UncheckedIcon in a List Box list items Tab?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287514#M2203</link>
      <description>Use SetTabItemIcon to draw a checkbox in a tab:&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;list.SetTabItemIcon( item, tabindex, DG::Icon( SysResModule, on ? DG::ListBox::CheckedIcon : DG::ListBox::UncheckedIcon) ;
&lt;/PRE&gt;

&lt;BR /&gt;
Handle the ListBoxClicked event:&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;void TestListDialog::ListBoxClicked( const DG::ListBoxClickEvent&amp;amp; ev )
{
	if ( ev.GetSource() == &amp;amp;mi_list )
	{
		short pos = ev.GetMouseOffset().GetX();
		short beg = mi_list.GetTabFieldBeginPosition( m_table.check );
		short end = mi_list.GetTabFieldEndPosition( m_table.check );
		if (  pos &amp;gt; end || pos &amp;lt; beg )
			return;

		OnListBoxCheckClicked( ev.GetListItem() );
	}
}
&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jul 2021 17:46:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287514#M2203</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2021-07-26T17:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to add Check box CheckedIcon and UncheckedIcon in a List Box list items Tab?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287515#M2204</link>
      <description>Thank you !</description>
      <pubDate>Tue, 27 Jul 2021 10:07:43 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-add-Check-box-CheckedIcon-and-UncheckedIcon-in-a-List-Box/m-p/287515#M2204</guid>
      <dc:creator>Jahidur</dc:creator>
      <dc:date>2021-07-27T10:07:43Z</dc:date>
    </item>
  </channel>
</rss>

