developer2012
asked on
Filter Datagrid base on Combobox selection(WPF)
Hi everyone,
How to filter data grid on combo box selection?
For example I am selecting a UID in combobox and click on view button then it should display all the records assoicated with it in the grid?
How do I achieve it?
THanks!
How to filter data grid on combo box selection?
For example I am selecting a UID in combobox and click on view button then it should display all the records assoicated with it in the grid?
How do I achieve it?
THanks!
How are you binding data to the DataGrid?
ASKER
Through a Dataset
Are you setting the ItemsSource for the DataGrid to the DataSet in code?
ASKER
I am doing it through XAML.
Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:datagrideg">
<Window.Resources>
<my:DataSet1 x:Key="DataSet1" />
<CollectionViewSource x:Key="TblSystemInformationViewSource" Source="{Binding Path=tblSystemInformation, Source={StaticResource DataSet1}}" />
</Window.Resources>
<Grid DataContext="{StaticResource TblSystemInformationViewSource}">
<ComboBox Height="39" HorizontalAlignment="Left" Margin="133,43,0,0" Name="ComboBox1" VerticalAlignment="Top" Width="147" DisplayMemberPath="DOT" ItemsSource="{Binding}" SelectedValuePath="UID" IsSynchronizedWithCurrentItem="True" />
<DataGrid AutoGenerateColumns="False" Height="250" HorizontalAlignment="Left" Margin="88,111,0,0" Name="DataGrid1" VerticalAlignment="Top" Width="311" ItemsSource="{Binding}" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="UIDColumn" Binding="{Binding Path=UID}" Header=" UID" IsReadOnly="True" Width="Auto" />
<DataGridTextColumn x:Name="DOTColumn" Binding="{Binding Path=DOT}" Header="DOT" Width="Auto" />
<DataGridTextColumn x:Name="StreetNameColumn" Binding="{Binding Path=StreetName}" Header="Street Name" Width="Auto" />
<DataGridTextColumn x:Name="CityColumn" Binding="{Binding Path=City}" Header="City" Width="Auto" />
<DataGridTextColumn x:Name="State" Binding="{Binding Path=State}" Header="State" Width="Auto" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just a general question . IS it a bad practice to use CollectionView?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.