[SOLVED] How to get ItemCount of shown items in a ListBox ?

Started by eri0o, Sat 10/08/2019 15:11:00

Previous topic - Next topic

eri0o

ItemCount gives me the total items in a ListBox, RowCount gives me total number of rows in a ListBox. But ListBoxes can be scrolled. Is there a way to get the number of items actually shown in a ListBox ?


eri0o

Manual is wrong again then it's not, you and I are saying the same thing with different wording:

https://github.com/adventuregamestudio/ags-manual/wiki/ListBox#rowcount

QuoteRowCount
readonly int ListBox.RowCount
Gets the number of rows that can be shown within the list box. This depends on the size of the list box, and does not depend on how many items are actually stored in the list box.

This property is read-only. To change the row count, adjust the height of the list box.

Example:

Display("You can currently see %d items from the listbox's contents", lstSaveGames.RowCount);
will display the number of rows that the listbox can display.

Edit: I did another test. I get the functionality described in the manual but I get a 0 on the first room load. Wait, now I see you and I talked about the same thing. The manual is correct.

Still, I don't know how to know if the page is scrolled.

Edit2:
Code: ags

_LIST BOX_
[ item a ]
[ item b ]
[ item c ]
[        ]
[        ]
[        ]
[        ]
__________


For a list box presented on the screen like the one "sketched" above, I need something that returns me 3, be the listbox scrolled or not. For the above, RowCount returns me 7.

Khris

So what does .ItemCount give? Should be 3, right?

eri0o

Yes. I recorded a video - I really suck at writing... Notice the empty slot on the end.


eri0o

Ok. I think I figured. There's a property I didn't knew called TopItem.

Code: ags

int VisibleItemCount(this ListBox*){
  int d =  this.ItemCount - this.TopItem-1;
  if(d < this.RowCount){
    return d;
  } 
  return this.RowCount;
}

Crimson Wizard

Oh, you were asking about items actually visible at the moment, that's weird but somehow I misunderstood.

SMF spam blocked by CleanTalk