cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum

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
2 REPLIES 2

Solution
bschwb
Advocate

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 (partially free) Add-Ons at www.bschwb.com/add-ons

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 🙂

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!