Quantcast
Viewing all articles
Browse latest Browse all 18858

wpf ef zipcode combobox question

Using wpf and ef 6.  I have a lookup table for zipcodes.  This table has zip, city, and state.  On a wpf window, there is a combobox for zip, a textbox for city, and a textbox for state.  How do I automatically supply the city and state based on the zipcode selected?

Code to bind combo:

        Dim zipCodeList = From z In _context.tlkpZipCodes _
                          Order By z.ZipCode
        Dim zipCodeSource = CType(Me.FindResource("ZipCodeLookup"), CollectionViewSource)
        zipCodeSource.Source = zipCodeList.ToList

Xaml:

<Window.Resources><CollectionViewSource x:Key="ZipCodeLookup" /></Window.Resources><Grid DataContext="{StaticResource MyResource}">
         ...snip...<Label Content="Zip:" HorizontalAlignment="Left" Margin="103,184,0,0" VerticalAlignment="Top"/><ComboBox Name="cboZip" HorizontalAlignment="Left" Margin="137,184,0,0" VerticalAlignment="Top" Width="120" 
                  DisplayMemberPath="ZipCode" 
                  ItemsSource="{Binding Source={StaticResource ZipCodeLookup}}" /><Label Content="City:" HorizontalAlignment="Left" Margin="99,210,0,0" VerticalAlignment="Top"/><TextBox Name="txtCity" HorizontalAlignment="Left" Height="23" Margin="137,210,0,0" TextWrapping="Wrap" 
                                  VerticalAlignment="Top" Width="120"/><Label Content="State:" HorizontalAlignment="Left" Margin="93,238,0,0" VerticalAlignment="Top"/><TextBox Name="txtState" HorizontalAlignment="Left" Height="23" Margin="137,238,0,0" TextWrapping="Wrap" 
                 VerticalAlignment="Top" Width="120"/>

For example, if the zipcode lookup table contains this row:

     10028, "New York", "NY"

and the user chooses 10028 from the combo, "New York" will appear in the city textbox and "NY" will appear in the state textbox.


Thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>