I have a combobox
and a datagrid
in my application. The datagrid has its itemsSource from its collectionViewSource and there are three ComboBoxItem
's in the combobox as warning/error/exception as shown in the image below.
How to display the selecteditem row details on the datagrid when the respective ComboxBoxitem
is selected.
this what I have tried.
Combobox - XAML
<ComboBox
SelectedValuePath="{Binding ElementName=dataGrid1,Path=SelectedItem.Type,Mode=OneWay}"
Grid.Column="1" Height="32" HorizontalAlignment="Left" Name="comboBox1" >
<ComboBoxItem Content="Warning"/>
<ComboBoxItem Content="Error"/>
<ComboBoxItem Content="Exception"/>
</ComboBox>
datagrid's XAML
<DataGrid AutoGenerateColumns="False"
IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" Name="dataGrid1">
is it possible to achieve this via XAML skipping code behind ? if not other suggestions are also most welcome.
This is a code sample that may helps you. It shows a Collection View Source, with a filter...
XAML
<Window x:Class="Ejemplos_EnlaceADatos.Figura5_12"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cmod="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:cine="clr-namespace:Ejemplos_EnlaceADatos.Cine"
Title="Lista de Films" Height="200" Width="300"
>
<Window.Resources>
<CollectionViewSource x:Key="films" Source="{x:Static cine:Filmes.Films}" Filter="Filter_Film">
<CollectionViewSource.SortDescriptions>
<cmod:SortDescription PropertyName="Título"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Window.Resources>
<ScrollViewer>
<StackPanel TextBlock.FontFamily="Segoe UI" Margin="6">
<TextBlock FontSize="16" FontWeight="Bold" Foreground="Navy">
Films:
</TextBlock>
<ItemsControl ItemsSource="{Binding Source={StaticResource films}}"/>
</StackPanel>
</ScrollViewer>
</Window>
Code Behind
using System.Windows;
using System.Windows.Data;
using Ejemplos_EnlaceADatos.Cine;
namespace Ejemplos_EnlaceADatos {
public partial class Figura5_12 : Window {
public Figura5_12() {
InitializeComponent();
}
void Filter_Film(object sender, FilterEventArgs e) {
e.Accepted = (e.Item is Film) && (((Film)e.Item).Género == Género.Mafia);
}
}
}
And filter like this:
Before
After
It is just an example of filtering, but is it with a regular items control.
You can make use of DataGrid's Filter,
Refer here for more details : http://msdn.microsoft.com/en-us/library/ff407126.aspx