Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to listbox data #1236

Closed
Methamane opened this issue Sep 11, 2021 · 3 comments · May be fixed by #1995
Closed

Add options to listbox data #1236

Methamane opened this issue Sep 11, 2021 · 3 comments · May be fixed by #1995
Labels
priority: low low priority type: feature New feature or request

Comments

@Methamane
Copy link

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:

  1. Have the callback data be the index of the item selected (perhaps a bool when setting up the listbox, i.e. return_index=True).
  2. 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()
@hoffstadt hoffstadt added the type: feature New feature or request label Sep 25, 2021
@hoffstadt hoffstadt added the priority: low low priority label Oct 13, 2021
@TheCDC
Copy link

TheCDC commented Oct 21, 2021

I have this issue as well. The listbox documentation does not seem to provide a canonical way to reference the selected item directly either by identity or by index.

Mstpyt added a commit to Mstpyt/DearPyGui-Fixes that referenced this issue Jan 5, 2023
@Nonoreve
Copy link

The Pull Request hasn't been merged, why is this closed ?
I would really enjoy this feature

@bandit-masked
Copy link
Collaborator

bandit-masked commented Jan 21, 2024

It was closed as part of a general clean up, as the number of issues was exceeding the developer time and issues were prioritized. I have flagged the PR today, so maybe it will be picked up again.

In the meantime, you could see if the following example offers any interesting workarounds for you.

https://github.com/hoffstadt/DearPyGui/wiki/Tools-and-Widgets#dpg-swiss-controls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low low priority type: feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants