How to show an item in listbox is selected without user click (C++ FMX, C++ Builder)?


I am trying to use the SetItemIndex method to programmatically select an item of a listbox. It’s a virtual method, so I understand I need to override it, but I’m not sure what that would look like or where I would put the code.

Alternatively, is there another method I should use to show that an item in a listbox is selected?

What my app looks like now:

What I want it to look like (without the user clicking):

I’m creating an app using C++ FireMonkey (FMX, using C++ Builder) to get user input from many screens. The listbox is to show the user where they are in the input process, and provide the ability to jump back several screens.

If they use the next button to navigate to the next screen, I want the listbox to automatically show the corresponding screen as selected.

Here are the relevant excerpts from my code:

class TFormMain : public TForm
__published: // IDE-managed Components
TListBox *leftSideBar_listbox;


__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)

And the error I get:

[bcc32c Error] TFormMain.cpp(29): ‘SetItemIndex’ is a protected member of ‘Fmx::Listbox::TCustomListBox’
FMX.ListBox.hpp(493): declared protected here

In FMX.ListBox.hpp line 493:


virtual void __fastcall SetItemIndex(const int Value);

relevant documentation:

(this post is about C# instead of C++)

Programmatically selecting an Item in a ListBox

Comments are closed.