DropdownField value changed event

So I’m using RegisterValueChangedCallback on my DropdownField to do some action when the user select a new value in the dropdown field.

My problem is that if I change the label of the dropdown field programmatically, it also triggers the RegisterValueChangedCallback.

DropdownField mydropdown = root.Q<DropdownField>("mydropdown");
mydropdown.RegisterValueChangedCallback(v => Debug.Log(v.newValue));
mydropdown.label = "New Label";     // triggers the function above

Is there a way to know what triggered the callback ?

Hi,

to change the value without triggering the callback use:

mydropdown.SetValueWithoutNotify(“value”);

2 Likes

Hi, thank you

Actually it is the label I want to change without triggering the callback, not the value. Is there a way to do that ?

Hi @crashoz ,
I have the same problem that you described .
Have you found a solution on how to set the dropdownfields label text without triggering the “ValueChangedCallback”?

I did a workaround by using a separate Label object for the DropDownField element and removing the Text in the child Label (in the UIBuilder) object of the DropDownField object.

Another solution would be to use the dropDownField.UnregisterValueChangedCallback method before changing the DropDownField.label property and after that register the callback again with: dropDownField.RegisterValueChangedCallback

1 Like