-
January 27th, 2012, 03:04 AM
#1
A text box that filters a datagrid (search)
Hello everyone, a newbie to Visual studio and programming in general. I use WPF and C#.
I have a datagrid that shows some observable collection data. I would like to create a search box that filters the datagrid. I have tried something like this
<UserControl x:Class="Inventar.Views.OpremaListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
>
<UserControl.Resources>
<CollectionViewSource x:Key="adressSource"
Source="{Binding AllAdress}">
<CollectionViewSource.SortDescriptions>
<ComponentModel:SortDescription PropertyName="LookupAdress"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<DockPanel Margin="5">
<Border DockPanel.Dock="Top"
Style="{StaticResource header}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Oprema ( " />
<TextBlock Text="{Binding AllAdress.Count}"/>
<TextBlock Text=")"/>
</StackPanel>
</Border>
<StackPanel DockPanel.Dock="Bottom"
Style="{StaticResource buttonPanel}">
<Button Content="Close"
Click="Close_Click"/>
</StackPanel>
<DataGrid Margin="5"
ItemsSource="{Binding Source={StaticResource adressSource}}"
AutoGenerateColumns="False"
Button.Click="OpenOprema_Click"
IsReadOnly="True"
Background="LightGray"
RowBackground="LightYellow"
AlternatingRowBackground="LightBlue"
>
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource openButton}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Inventurni Broj" Binding="{Binding InventurniBroj}" />
<DataGridTextColumn Header="Naziv" Binding="{Binding Naziv}" />
<DataGridTextColumn Header="Dobavljac" Binding="{Binding Dobavljac}" />
<DataGridTextColumn Header="Zaduzio" Binding="{Binding Adress.Contact.Zaduzio}" />
<DataGridTextColumn Header="Vrijednost" Binding="{Binding Vrijednost}" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</UserControl>
While the search code is this
public void Search(string criteria)
{
if (!string.IsNullOrEmpty(criteria) && criteria.Length > 2)
{
CurrentAdress = new ObservableCollection<Adress>(
_adressRepository.FindByLookup(criteria));
StatusText = string.Format("{0} zaduzenih pronađeno.", CurrentAdress.Count);
}
else
{
CurrentAdress = new ObservableCollection<Adress>(_adressRepository.FindAll());
StatusText = "Prikaz svih zaduzenih.";
}
}
But it doesn't work. Any ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|