-
-
Notifications
You must be signed in to change notification settings - Fork 732
Description
Is your feature request related to a problem? Please describe.
When I click on an item in a listbox the data being sent to the callback function is just the string of the item, this is perfectly fine when you have items with unique strings. In my instance I'm using the listbox to display a list of transactions and some of them have identical string names, and then I don't know exactly which of those transactions was selected.
Describe the solution you'd like
I think that one of the following would suffice to solve the problem:
- Have the callback data be the index of the item selected (perhaps a bool when setting up the listbox, i.e. return_index=True).
- Have the list of items given to the listbox as a list of tuples instead of strings, and when an item is selected the data returned would be the corresponding tuple. The first element in the tuple could be the string to display, and the other elements could be custom ids or anything else that is needed.
Describe alternatives you've considered
At the moment my solution is just adding the id number in the items string, that works because I can extract the id from the string but the downside is that the id is displayed.
Additional context
Here's a minimal example showing that I don't know which of "item1" was clicked.
import dearpygui.dearpygui as dpg
def item_clicked(sender, data):
print(data)
with dpg.window():
dpg.add_listbox(items=["item1", "item1", "item2"], callback=item_clicked)
dpg.start_dearpygui()