cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
Dayiz
Booster

How does AppendItem() work for ListBox?

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 Solution

Accepted Solutions

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

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Go to post

2 Replies 2

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

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com
Dayiz
Booster

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 🙂

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!