Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / WPF

Cascading Dropdown & Multiselect Option in ListBox Using WPF

Rate me:
Please Sign up or sign in to vote.
4.85/5 (13 votes)
10 May 2009CPOL3 min read 60.3K   2K   14  
An attempt to show the flexibility of binding in WPF using MVVM pattern using cascading dropdown/combo box & listbox
<Window x:Class="CascadingDropDown.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="203" Width="656" Loaded="Window_Loaded">
    <Grid>
        <GroupBox Header="SimpleCascadingDropdown" Margin="12,12,0,0" Name="grpCascadingDropdown" Height="147" VerticalAlignment="Top" HorizontalAlignment="Left" Width="239">
            <Grid Height="101" Width="224">
                <Grid.RowDefinitions>
                    <RowDefinition Height="53*" />
                    <RowDefinition Height="52*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="8*" />
                    <ColumnDefinition Width="235*" />
                </Grid.ColumnDefinitions>
                
                
                <Label HorizontalAlignment="Left" Margin="6,6,0,23" Name="lblCountry" Width="59" Grid.ColumnSpan="2">Country</Label>
                <ComboBox Margin="54,7,49,23" Name="cmbCountry" ItemsSource="{Binding SingleCountryList}" DisplayMemberPath="CountryName" IsSynchronizedWithCurrentItem="True" SelectionChanged="cmbCountry_SelectionChanged" Grid.Column="1" />
              
                <Label Margin="7,36,0,41" Name="lblState" HorizontalAlignment="Left" Width="50" Grid.Column="1" Grid.RowSpan="2">State</Label>
                <ComboBox Margin="54,38.5,49,43.5" Name="cmbState" ItemsSource="{Binding SingleStateList}" DisplayMemberPath="StateName" IsSynchronizedWithCurrentItem="True" SelectionChanged="cmbState_SelectionChanged" Grid.Column="1" Grid.RowSpan="2" />
                <Label Margin="7,11,0,13" Name="lblCity" HorizontalAlignment="Left" Width="31" Grid.Column="1" Grid.Row="1">City</Label>
                <ComboBox Margin="56,16,49,13" Name="cmbCity" ItemsSource="{Binding SingleCityList}" DisplayMemberPath="CityName" IsSynchronizedWithCurrentItem="True" Grid.Column="1" Grid.Row="1" />
            </Grid>
        </GroupBox>
        
        
        <GroupBox Header="SimpleCascadingListbox" Margin="291,12,79,0" Name="grpCascadingListbox" Height="147" VerticalAlignment="Top">
            <Grid Height="209">
                <Label Height="28" Margin="6,12,0,0" Name="lblNewCountry" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51">Country</Label>
                <ListBox Margin="60,14,52,0" Name="lstCountry" Height="26" VerticalAlignment="Top" ItemsSource="{Binding MultipleCountryList}" DisplayMemberPath="CountryName" SelectionMode="Multiple" IsSynchronizedWithCurrentItem="True" SelectionChanged="lstCountry_SelectionChanged"/>
                <Label Margin="10,46,0,0" Name="lblNewState" HorizontalAlignment="Left" Width="43" Height="24.862" VerticalAlignment="Top">State</Label>
                <ListBox Margin="59,46,55,0" Name="lstState" Height="27.362" VerticalAlignment="Top" SelectionMode="Multiple" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding MultipleStateList}" DisplayMemberPath="StateName" SelectionChanged="lstState_SelectionChanged"/>
                <Label Margin="7,86.361,0,96.362" Name="lblNewCity" HorizontalAlignment="Left" Width="46">City</Label>
                <ListBox Margin="59,88.723,55,96.362" Name="lstCity" SelectionMode="Multiple" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding MultipleCityList}" DisplayMemberPath="CityName"/>
            </Grid>
        </GroupBox>
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions