Strange dictionary behavior

I wanted to use a dictionnary to get a text (value of dictionnary) when a button is pressed.
What is strange is that I get the button text (caption) , but not the value from dictionnary
And I never get "not found" even with buttons not in the dictionnary....
Can you help me understand what is wrong ?
The result is display in a TextBox .

I am not sure dictionaries can work with components as keys.

I recommend using a list of lists (table) and lookup in pairs instead.

Why is the first part of the event obscured?

Is it obscene?

Thanks for your help.
I hide the first part to focus on the problem.
In fact, the first part uses a list as a search for more "simple" buttons.
I thought a dictionary was more readable...
I will test with the list of pairs.

If the list of pairs does not work, show more code.

We have strong stomachs.

1 Like

I created a list of pairs, but I left the call to the dictionary on this list: it works.
Obviously there is not so much difference between dictionary and list ...
So why can I use component as index in the list, but not on the dictionary ? strange :pensive:

Dictionaries are optimized for speed .
They also provide uniqueness and JSON conversion ease.

The keys must be text.

Components are complex and they breathe data, and need to be kept in list item cages.

There is nothing "wrong" with using components in dictionaries, just may be about how you use them. It may make more sense to reverse your key/values ?


and remember that components are generated at runtime, so their names/values change on each start of the app.

I use "when any button click" so I only know the button clicked, and I want to retreive the data to send affected to this button.
if it was possible to retrieve the name of the button as defined in the designer, it would be fine, but as it is impossible I use a list.

You can always test for a property of the component/button(e.g. text or background colour) which might be used as the key in the dictionary

Unfortunately, there are no meaningless properties that I don't use.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.