Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I populate my second combobox based on other combobox selected item
    primarykey
    data
    text
    <p>My Question is i want to see my artist combobox selected artist related albums in my albums combobox.</p> <p>I found out code example on this site and it is similar to my problem:</p> <p>but I didn't understand how we get the SelectedArtist value. I pluged this code and test it it keeps giving me null ... I tried to assign artistName to SelectedArtist from the lists of Artits I have but that wasn't successfull: </p> <p>Can some one help me how i can find the SelectedArtist value before i check if its null or not</p> <p>I currently have a ComboBox which is populated with Artist names and I need to bind it to another comboBox of albums once the Artist is selected. </p> <p>These are set up as follows in my view: XAML</p> <pre><code>&lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="65,81,0,0" Name="comboBox1" ItemsSource="{Binding Artists}" SelectedItem="{Binding SelectedArtist}" VerticalAlignment="Top" Width="120" /&gt; &lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="65,115,0,0" Name="comboBox2" VerticalAlignment="Top" ItemsSource="{Binding Albums}" SelectedItem="{Binding SelectedAlbums}" Width="120" /&gt; private void initialiseArtists() { MusicDataClassesDataContext dataClasses = new MusicDataClassesDataContext(); artistList = (from m in dataClasses.tblArtists select m.ArtistName).ToList(); } public List&lt;String&gt; Artists { get { return this.artistList; } } public List&lt;String&gt; Albums { set { initialiseAlbums(); } get { return this.albumList; } } public string SelectedArtist { set { this.selectedArtist = value; initialiseAlbums(); } } private void initialiseAlbums() { if (selectedArtist != null) { MusicDataClassesDataContext dataClasses = new MusicDataClassesDataContext(); var getArtist = dataClasses.tblArtists.FirstOrDefault(band =&gt; band.ArtistName== selectedArtist); albumList = (from album in dataClasses.tblAlbums where album.ArtistID == getArtist.ArtistID select album.AlbumName).ToList(); OnPropertyChanged("Albums"); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) {if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload