How to Disable one of the items in a Tlistbox!

Asked

Viewed 29 times

0

I wish I could be Disable one of the items in a Tlistbox.
And I’ve tried the following ways and I haven’t succeeded.

ListBoxMenu.ItemIndex(0).Enabled := False;
ListBoxMenu.ItemIndex[0].Enabled := False;

When I put these lines presents this msg.

[dcc32 Error] Untprincipal.pas(6420): E2016 Array type required

Have I tried searching on the website of http://docwiki.embarcadero.com/ but I couldn’t find anything to help me.

1 answer

2

According to the documentation, the property Itemindex, specifies the Index of the Item selected. So, it returns an integer and not the Item itself.

To recover the item you can use the method Itembyindex, or the property Listitems.

Thus remaining:

ListBoxMenu.ItemByIndex(0).Enabled := False;

or so

ListBoxMenu.ListItems[0].Enabled := False;

This considering that you are using Firemonkey, which gives a greater freedom to work with the items by the fact that they are Tlistboxitem.

Now if you are using VCL where the Listbox items are the lines of a Tstrings. Ai complicates. If this is the case I suggest you remove the item from the list instead of trying to disable.

  • Wouldn’t Have the menus change the color of each Tlistbox item?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.