BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

How does AppendItem() work for ListBox?

Dayiz
Booster

Hello everyone,

 

I've been working my way through the "Dialog Manager" Doc and the example addons provided by Graphisoft.

In the DG_Test AddOn is an example for a ListBox called "OwnerDrawnListBoxPalette.cpp". There is a function called "GetObjects()":

 

Spoiler
void OwnerDrawnListBoxPalette::GetObjects()
{
  listBox.DeleteItem (DG::ListBox::AllItems);
  // add items to the listbox
  data.elements.Clear (true /*keepCapacity*/);
  data.elementImages.Clear ();
  ACAPI_Element_GetElemList (API_ZombieElemID, &data.elements);
  for (UIndex i = 0; i < data.elements.GetSize (); ++i) {
    listBox.AppendItem ();
    if (i % 2)
      listBox.SetItemBackgroundColor (DG_LIST_BOTTOM, Gfx::Color::LightGray);
  }
}

As I understand, the function clears the Items in the ListBox and fills it again. But how exactly does listBox.AppendItem() work? 

ACAPI_Element_GetElemList (API_ZombieElemID, &data.elements) gets an elementlist, where data is a struct and data.elements is a GS::Array<API_Guid>.

So if we iterate in the for loop over the size of the GS::Array, how does "listBox.AppendItem ()" know which item to add? In the header file I saw it doesn't take any parameters (void), so I'm even more confused on how this function is supposed to work.

 

Dear Regards

Dayiz

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Hi Dayiz,

 

"listBox.AppendItem ()" adds an item to the end of the list box. So in the example you posted, for each iteration of the loop there is a new item added to the list box and then you can reference this item immediately with "DG_LIST_BOTTOM" (there is also "listBox.BottomItem") which will always point to the currently last item.

In the end the loop body was executed exactly so many times as the size of the GS::Array, so the listBox will have that amount of items.

Best,
Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com

View solution in original post

2 REPLIES 2
Solution

Hi Dayiz,

 

"listBox.AppendItem ()" adds an item to the end of the list box. So in the example you posted, for each iteration of the loop there is a new item added to the list box and then you can reference this item immediately with "DG_LIST_BOTTOM" (there is also "listBox.BottomItem") which will always point to the currently last item.

In the end the loop body was executed exactly so many times as the size of the GS::Array, so the listBox will have that amount of items.

Best,
Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com

I was confused how empty Items in a listbox can get their value. But now that i figured out how the update function for list boxes works, the append function makes sense.

thank you 🙂

Learn and get certified!