Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

collection binding to combobox in datagrid (different collection for each datagrid row combobox)

$
0
0

Hi,

I am trying to bind a collection to datagrid combobox and this collection is different for each row in the data grid.

pls have a look at the below code , I could not able to bind the Artist collection for each row in the combobox.

Can someone help on this please.

Note: Songs is observable collection of Song Class.

public
 class Song
{
#region
 Properties
public string ArtistName { get; set; }
public string SongTitle { get; set; }
public List<Artist> Artist { get; set; }
#endregion
}
public class Artist
{
public string ArtistCountry { get; set; }
}
XMAL:<DataGrid><DataGridTextColumn Header="Artist Name" Binding="{Binding ArtistName}" /><DataGridTextColumn Header="Song Title" Binding="{Binding SongTitle}" /><DataGridTemplateColumn Header="Artist Country"><DataGridTemplateColumn.CellTemplate><DataTemplate><ComboBox 
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Songs}"
SelectedValuePath="Artist.ArtistCountry"
DisplayMemberPath="Artist.ArtistCountry"
SelectedItem="{Binding Path=Artist}"
/></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid>



Viewing all articles
Browse latest Browse all 18858

Trending Articles



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