Python wrapper (rpw) combobox

Is possible to control the contents of one Combobox from another.
So that if the user selects an entry in one comboxbox then the other combobox list changes based on the selection?

Eg.
Combobox1 (user selects Option 1) → Combobox2 (list = 1,2,3)
Combobox1 (user selects Option 2) → Combobox2 (list = 4,5,6)

Hope this makes sense

Check out the colour splasher code. It is a bit convoluted but works that way for this script.

To keep it simpler, you could display the combo boxes in sequence as a first step

Create OptionValue class

class OptionValue:
    def __init__(self, name):
        self._name = name

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, value):
        self._name = value

Create Option class

class Option:
    def __init__(self, name):
        self._name = name
        self._values = []

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, value):
        self._name = value

    @property
    def values(self):
        return self._values

    @option_values.setter
    def values(self, value):
        self._values = value

Create xaml file

<StackPanel>
    <ComboBox
        Width="150"
        SelectedItem="{Binding Option}"
        ItemsSource="{Binding Options}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding name}" />
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

    <ComboBox
        Width="150"
        ItemsSource="{Binding Option.values}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding name}" />
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>
</StackPanel>
1 Like

I will look into it

Appreciate you assistance.
Thank you

1 Like

Been trying to understand how to incorporate this into my code… not having much luck unfortunately.
Trying to find example code of it’s implantation so I can study and understand how it goes together

@EddieS, my button with bindings and MVVM

1 Like