ListBox or ListView?

Hi, I’m using gtkmm4 and I’m wondering whether I should use ListBox or ListView in my app.
The widget should contain text items, sometimes there will be 2 columns, and sometimes one.
There are NOT supposed to be many items but I would like to load them from a file easily.
The selection will always be a single row selection, sorting and filtering are not yet decided.
Can anyone suggest the most suitable widget? Code examples are also welcome

ListBox is your best choice. it contains ListBoxRow to hold children widgets, one or more.

1 Like

You should use ListBox if you know beforehand the number of rows you’ll have and they won’t change for the duration of the application; or, if you have a variable number of rows, that the maximum number won’t get near 100.

For dynamically populated lists, with an arbitrarily large number of rows, you want ListView instead.

For instance:

  • a settings UI, with a known number of options, should use ListBox
  • a file list widget should use ListView

The gtk4-demo application has demos and code for both widgets, written in C.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.