I am loading one grid that will need to be filtered by user input of a value in a seperat textbox. The filter is a CONTAINS filter on one column of the grid.
Basically as the user types, the available values need to go down to better and better match the input. Do you guys have a good example of this?
Note: Values are plain text CONTAINS matching, so no special custom filters seem to be needed.
Basically as the user types, the available values need to go down to better and better match the input. Do you guys have a good example of this?
Note: Values are plain text CONTAINS matching, so no special custom filters seem to be needed.
6 Answers, 1 is accepted
0
Hi Dmitry,
Please check this demo for more info:
http://demos.telerik.com/wpf/?GridView/Search
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Please check this demo for more info:
http://demos.telerik.com/wpf/?GridView/Search
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Dmitry
Top achievements
Rank 1
answered on 27 Apr 2009, 02:35 PM
Thank you for the pointer, but what code is inside of the custom class CustomFilterDescription?
0
Hello Dmitry,
You can find the CustomFilterDescription class here :
<radcontrols installation folder>\Examples.CS\GridView\Search\CustomFilterDescription.cs
I'm also attaching the requested custom class for your convenience.
Please don't hesitate to contact us if you have other questions.
Kind regards,
Anastasia
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can find the CustomFilterDescription class here :
<radcontrols installation folder>\Examples.CS\GridView\Search\CustomFilterDescription.cs
I'm also attaching the requested custom class for your convenience.
Please don't hesitate to contact us if you have other questions.
Kind regards,
Anastasia
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kenny
Top achievements
Rank 1
answered on 18 May 2009, 07:20 PM
Hi there,
I'm working on a form with filtering by Containts as well, but using LINQ instead of using the ObjectDataProvider, but everytime the filter text got entered, the grid returned nothing (no records). I'm sure it's on my part since I'm pretty new to this WPF stuffs, so if you can help, that would be great. Here are the codes:
1. I have a "MusicData" class that acts as the gateway for me to get the data using LINQ.
public class MusicData |
{ |
public int MusicID { get; set; } |
public string Title { get; set; } |
public string Title2 { get; set; } |
public string Artist { get; set; } |
public string Artist2 { get; set; } |
public string Key { get; set; } |
public string Path { get; set; } |
public string MP3 { get; set; } |
public static Notesnhac NotesnhacDataContext = new Notesnhac("Notesnhac.sdf"); |
public static IQueryable<MusicData> GetMusicSheets() |
{ |
var MusicSheets = NotesnhacDataContext.MusicSheets.Select(m => new MusicData |
{ |
MusicID = m.ID, |
Title = m.TITLE, |
Artist = m.ARTIST, |
Key = m.KEY |
}); |
return MusicSheets; |
} |
} |
2. In my XAML code behind file, Windows1.xaml.cs, I have a BindGrid() method that does the binding and call this method when this window got initilized, as well as the FilterValue_TextChanged method copied from the Example:
public Window1() |
{ |
InitializeComponent(); |
this.FilterTextBox.Focus(); |
BindGrid(); |
} |
private void BindGrid() |
{ |
var MusicSheets = MusicData.GetMusicSheets(); |
radGridView1.ItemsSource = MusicSheets; |
} |
private void FilterValue_TextChanged(object sender, TextChangedEventArgs e) |
{ |
if (this.FilterTextBox.Text.Length >= 1) |
{ |
IEnumerable<string> propertyNames = from GridViewColumn column in this.radGridView1.Columns |
select column.UniqueName; |
this.radGridView1.FilterDescription = new CustomFilterDescription(this.FilterTextBox.Text, propertyNames, false); |
} |
else |
{ |
this.radGridView1.FilterDescription = null; |
} |
} |
} |
3. I've added the TextBox and couple columns for the XAML file as supposed:
<telerik:RadGridView Name="radGridView1" telerik:Theming.Theme="Caramel" |
ShowGroupPanel="False" IsFilteringAllowed="False" |
Foreground="Black" Margin="0,30,0,0" AutoGenerateColumns="False"> |
<telerik:RadGridView.Columns> |
<telerik:GridViewDataColumn UniqueName="Title" HeaderText="Title" /> |
<telerik:GridViewDataColumn UniqueName="Artist" HeaderText="Artist" /> |
<telerik:GridViewDataColumn UniqueName="Key" HeaderText="Key" /> |
</telerik:RadGridView.Columns> |
</telerik:RadGridView> |
4. I've modified the SatisfiesFilter method in the CustomFilterDescription class to match my MusicData object. I think this is where I'm not sure what to do and thus, it didn't returned anything when I did the filter:
public override bool SatisfiesFilter(object dataItem) |
{ |
MusicData MusicSheets = (MusicData)dataItem; |
if (string.IsNullOrEmpty(this.filterValue) || MusicSheets == null) |
{ |
return false; |
} |
Type myDataType = MusicSheets.GetType(); |
IEnumerable propertyValues = from property in myDataType.GetProperties() |
where this.filterPropertyNames == null || this.filterPropertyNames.Contains(property.Name) |
select property.GetValue(MusicSheets, null); |
return (from object propertyValue in propertyValues |
where this.CheckPropertyValue(propertyValues) |
select propertyValue).Any(); |
} |
Any help is appreciated.
Thanks,
Kenny.
0
Hello Kenny,
Here is the mistake:
You are passing the whole IEnumerable to the CheckPropertyValue method (which will always return false), where you actually should pass each concrete propertyValue. Remove the "s" I have highlighted in red and everything should work as expected. I hope this helps.
Please, do not hesitate to contact us if you have any further questions.
Greetings,
Ross
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Here is the mistake:
return (from object propertyValue in propertyValues |
where this.CheckPropertyValue(propertyValues) |
select propertyValue).Any(); |
You are passing the whole IEnumerable to the CheckPropertyValue method (which will always return false), where you actually should pass each concrete propertyValue. Remove the "s" I have highlighted in red and everything should work as expected. I hope this helps.
Please, do not hesitate to contact us if you have any further questions.
Greetings,
Ross
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kenny
Top achievements
Rank 1
answered on 20 May 2009, 02:41 PM
Hi Ross,
Thank you so much for your help, that fixed the problem :)
Kenny.