Hello together,
I use the following code :
<Grid>
<ListView IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding CollectionMember}" SelectionMode="Single" HorizontalAlignment="Left" Height="143" Margin="23,21,0,0"
VerticalAlignment="Top" Width="309">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="120"/>
<GridViewColumn Header="Code" DisplayMemberBinding="{Binding CodeCountry}" Width="60"/>
</GridView>
</ListView.View>
</ListView>
<TextBox Text="{Binding CollectionMember.CurrentItem.Name}" HorizontalAlignment="Left" Height="23" Margin="23,187,0,0" VerticalAlignment="Top" Width="309"/>
<ComboBox SelectedValue="{Binding CollectionMember.CurrentItem.CodeCountry}" SelectedValuePath="Code" ItemsSource="{Binding ListCountry}" HorizontalAlignment="Left" Margin="23,231,0,0"
VerticalAlignment="Top" Width="309">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
public partial class MainWindow : Window
{
private DC dc = null;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
dc = new DC();
dc.CollectionMember.Add(new Member { Name = "Steve", CodeCountry = "US" });
dc.CollectionMember.Add(new Member { Name = "Piere", CodeCountry = "FR" });
dc.CollectionMember.Add(new Member { Name = "Hans", CodeCountry = "DE" });
dc.CollectionMember.Add(new Member { Name = "Rocco", CodeCountry = "IT" });
dc.ListCountry.Add(new Country { Code = "US", Name = "USA" });
dc.ListCountry.Add(new Country { Code = "FR", Name = "France" });
dc.ListCountry.Add(new Country { Code = "DE", Name = "Deutschland" });
dc.ListCountry.Add(new Country { Code = "IT", Name = "Italia" });
DataContext = dc;
}
}
public class Member
{
public string Name { get; set; }
public string CodeCountry { get; set; }
}
public class Country
{
public string Code { get; set; }
public string Name { get; set; }
}
public class DC
{
private ObservableCollection<Member> _CollectionMember = new ObservableCollection<Member>();
public ObservableCollection<Member> CollectionMember
{
get { return _CollectionMember; }
set { _CollectionMember = value; }
}
private List<Country> _ListCountry = new List<Country>();
public List<Country> ListCountry
{
get { return _ListCountry; }
set { _ListCountry = value; }
}
}
Code Download via:
http://www.file-upload.net/download-10343926/CurrentItem.zip.html
If I change the TextBox the Collection will be synchronized, but not so with the ComboBox.
Why does the TextBox working but not the ComboBox?
Thanks you for your help.
Regards
Torsten