Is there a way to designate an Item as disabled and unselectable in ListPicker

I have a database with certain records flagged as '0', meaning inactive and other records flagged as 1 meaning active.

Is there a way to display ALL the items in a database (SELECT * FROM table_name) BUT to DISABLE those flagged 0 in the database so the user can see them but NOT select them?

Any help, appreciated.

Thanks

Show disabled versus enabled options in a ListPicker differently and not enable the ListPicker to select the 'disabled' options by not allowing some items to be selected ? Not without some coding . What you can do with the ListPicker that is part of App Inventor is described in ListPicker .

You cannot highlight some items differently than other items and perhaps gray them out..

DISABLE those flagged 0 in the database so the user can see them but NOT select them
[/quote]

You don't disable the database; you disable what you allow the ListPicker to select and possibly in your List of items show item1, item2(disabled), item3 by modifying the file you use to display the List items.

Some work arounds:

  1. Provide two ListPickers; a ListPicker showing the items you want to show enabled and a second ListPicker showing the items you want the user to see but are disabled by limiting what is shown in each ListPicker populating the first ListPicker only with the items the User can work with (those flagged 1) and the second LP that only shows those items that cannot be used.

  2. Display both enabled and disabled items in a single ListPicker, Use Blocks (If..then.else statements) in the AfterPicking to only provide an action for the active items. When you load the ListPicker from your database, flag the items (0 , 1) and add a note to the 0's as disabled items as shown in the ListPicker. (Don't change the List, just modify what you display in the picker).

  3. Use other work around methods you can conceive.

You could mark your Elements with [_] or [X] in front of them to show their status.

This sample project does that, but responds by flipping the status when selected.
You would need to revise that for your needs.

ah, Thanks for that. I understand what you think about doing two listboxes but that very much defeats the object. I WANT the user to see the entire list as ONE unit. But thanks. It seems as if there isnt a way you do a for each which changes the colour even on the flag bit being either high or low???

Wow..... Thanks but way over my head...... Wouldnt it just have been easy enough for there to be an enable/disable function? I wish.

Correct.

So instead of two ListPickers m use option #2 I suggested. You cannot change an item color but you can add a text flag to how each item is displayed. If you select an item without a disabled flag using the ListPicker.AfterPicking, it will select the item and do what you want. To do that, code so that if the flag appears in the item display clicking on that item provides a Notification that that item is disabled instead of providing an action.

What is so difficult with this? You already usethe AfterPicking block to do something when an item is selected.

Perhaps you should show your existing blocks showing how you use the ListPicker and do a screen capture of the contents of you ListPicker list. Might be able to show you how to do it.

You do not share any information about your database so here is a generic example:

!
Select Item b (which is flagged as disabled) and a Notifier tells the user the item is disabled. :slight_smile:

disabledListPickerItems2

Select Item c and the Notifier indicates that item c is usable. Do something with it. What happens depends on the code in the ListPicker.AfterPicking event handler. In this example, what happens is determined by the 'name' of the item selected. Select an item based on its index(LP.SelectionIndex) or name (ListPicker.Selection). The example selects based on the 'name posted as a ListPicker item.

What you do depends on your database. Create a List of all the items in your data base and create a List of those items flagged 0. You probably do not need an sql statement but maybe you do, depending on your database. Use those two Lists to determine what you display in the ListPicker. This example designates an Item as disabled and makes it 'unselectible' (actually it can be selected but nothing will happen other than the posting of a message) in the ListPicker . Other items can be selected so you can do something with them.

Wow, you went to so much trouble. Thank you VERY MUCH. Ive taken some of what you suggested and ised it.

Much obliged

Kind Regards