This question is locked. New answers and comments are not allowed.
Good day Telerik Team,
I have implemented your search as you type functionality using your CustomFilterDescriptor.cs. it works fine for a simple collection of records.
When I created a treeview of project components and structure, where user can choose group of records to be presented in the Radgridview, and when i had search something on a searchtextbox area there are still data that is not part of the data i am looking for or when i type something which is not found in the records, still there appear some record. The records are retrieve from the database by just clicking the treview(project) or component/structure of the project.
I itemsource the treeview
I still use your code for the CustomFilterDescriptor.cs
for the mainpage.Xaml.cs
for the RadGridview
and for the search Area
Hoping for your response,
Aubrey :')
I have implemented your search as you type functionality using your CustomFilterDescriptor.cs. it works fine for a simple collection of records.
When I created a treeview of project components and structure, where user can choose group of records to be presented in the Radgridview, and when i had search something on a searchtextbox area there are still data that is not part of the data i am looking for or when i type something which is not found in the records, still there appear some record. The records are retrieve from the database by just clicking the treview(project) or component/structure of the project.
this.TreeViewSource(); private void DataGridLoaded(object sender, RoutedEventArgs e) { try { ReportsServiceClient client = new ReportsServiceClient(); client.DataGridCompleted += new EventHandler<DataGridCompletedEventArgs>(client_getAllEventsCompleted); client.DataGridAsync((listProject.Children.ElementAt(0) as CheckBox).Content.ToString()); } catch (CommunicationException) { } } ObservableCollection<Structure> gridevent; private void client_getAllEventsCompleted(object s, DataGridCompletedEventArgs a) { ObservableCollection<ReportsUI.ReportsService.Structure> list = a.Result; ObservableCollection<Structure> st = new ObservableCollection<Structure>(); for (int icount = 0; icount < list.Count; icount++) { // st.Add(new Structure { ID = list[icount].ID, ParentID = list[icount].ParentID, Name = list[icount].Name }); st.Add( new Structure { EventID = list[icount].EventID, EventDate = list[icount].EventDate, EventTime = list[icount].EventTime, StructureName = list[icount].StructureName, ComponentName = list[icount].ComponentName, TaskName = list[icount].TaskName, ObservationEvent = list[icount].ObservationEvent, ObservationSubEvent = list[icount].ObservationSubEvent, Anomaly = list[icount].Anomaly, CPValue = list[icount].CPValue, AnomalyClassification = list[icount].AnomalyClassification, EventCode = list[icount].EventCode, LocationClock = list[icount].LocationClock, Comment = list[icount].Comment, Easting = list[icount].Easting, Northing = list[icount].Northing, KP = list[icount].KP, FrameTime = list[icount].FrameTime, NavTimeStamp = list[icount].NavTimeStamp, TaskID = list[icount].TaskID, Elevation = list[icount].Elevation }); } rgvReportData.ItemsSource = st; gridevent = st; rgvReportData.IsBusy = false; } private void TreeViewSource() { for (int i = 0; i < listProject.Children.Count; i++) { CheckBox box = listProject.Children.ElementAt(i) as CheckBox; if (box.IsChecked == true) { ReportsServiceClient client = new ReportsServiceClient(); client.TreeViewCompleted += new EventHandler<TreeViewCompletedEventArgs>(client_getTreeViewCompleted); client.TreeViewAsync((listProject.Children.ElementAt(i) as CheckBox).Content.ToString()); } } } List<DataItemCollection> treeviewCollection = new List<DataItemCollection>(); private void client_getTreeViewCompleted(object s, TreeViewCompletedEventArgs a) { ObservableCollection<ReportsUI.ReportsService.tree1> list = a.Result; //treeviewCollection[counter] = new DataItemCollection(); DataItemCollection item = new DataItemCollection(); for (int icount = 0; icount < list.Count; icount++) { item.Add(new tree1 { ID = list[icount].ID, ParentID = list[icount].ParentID, Name = list[icount].Name }); //(treeviewCollection.ElementAt(counter) as DataItemCollection).Add(item); //(treeviewCollection.ElementAt(counter) as DataItemCollection).Add(new tree1 { ID = list[icount].ID, ParentID = list[icount].ParentID, Name = list[icount].Name }); //treeviewCollection[counter].Add(new tree1 { ID = list[icount].ID, ParentID = list[icount].ParentID, Name = list[icount].Name }); } treeviewCollection.Add(item); item = null; PopulatePanelbar(treeviewCollection.Count-1); PopulatePanelbarChart(treeviewCollection.Count-1); }I still use your code for the CustomFilterDescriptor.cs
using System;using System.Collections.Generic;using System.Globalization;using System.Linq.Expressions;using Telerik.Windows.Controls;using Telerik.Windows.Data;namespace ReportsUI{ public class CustomFilterDescriptor : FilterDescriptorBase { private readonly CompositeFilterDescriptor compositeFilterDesriptor; private static readonly ConstantExpression TrueExpression = System.Linq.Expressions.Expression.Constant(true); private string filterValue; public CustomFilterDescriptor(IEnumerable<GridViewDataColumn> columns) { this.compositeFilterDesriptor = new CompositeFilterDescriptor(); this.compositeFilterDesriptor.LogicalOperator = FilterCompositionLogicalOperator.Or; foreach (GridViewDataColumn column in columns) { this.compositeFilterDesriptor.FilterDescriptors.Add(this.CreateFilterForColumn(column)); } } public string FilterValue { get { return this.filterValue; } set { if (this.filterValue != value) { this.filterValue = value; this.UpdateCompositeFilterValues(); this.OnPropertyChanged("FilterValue"); } } } protected override System.Linq.Expressions.Expression CreateFilterExpression(ParameterExpression parameterExpression) { if (string.IsNullOrEmpty(this.FilterValue)) { return TrueExpression; } try { return this.compositeFilterDesriptor.CreateFilterExpression(parameterExpression); } catch { } return TrueExpression; } private IFilterDescriptor CreateFilterForColumn(GridViewDataColumn column) { FilterOperator filterOperator = GetFilterOperatorForType(column.DataType); FilterDescriptor descriptor = new FilterDescriptor(column.UniqueName, filterOperator, this.filterValue); descriptor.MemberType = column.DataType; return descriptor; } private static FilterOperator GetFilterOperatorForType(Type dataType) { return dataType == typeof(string) ? FilterOperator.Contains : FilterOperator.IsEqualTo; } private void UpdateCompositeFilterValues() { foreach (FilterDescriptor descriptor in this.compositeFilterDesriptor.FilterDescriptors) { object convertedValue = DefaultValue(descriptor.MemberType); try { convertedValue = Convert.ChangeType(this.FilterValue, descriptor.MemberType, CultureInfo.CurrentCulture); } catch { } if (descriptor.MemberType.IsAssignableFrom(typeof(DateTime))) { DateTime date; if (DateTime.TryParse(this.FilterValue, out date)) { convertedValue = date; } } descriptor.Value = convertedValue; } } private static object DefaultValue(Type type) { if (type.IsValueType) { return Activator.CreateInstance(type); } return null; } }}for the mainpage.Xaml.cs
private CustomFilterDescriptor customFilterDescriptor;
private void FilterValue_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e){ this.CustomFilterDescriptor.FilterValue = this.txtSearch.Text; this.txtSearch.Focus();} public CustomFilterDescriptor CustomFilterDescriptor{ get { if (this.customFilterDescriptor == null) { this.customFilterDescriptor = new CustomFilterDescriptor(this.rgvReportData.Columns.OfType<GridViewDataColumn>()); this.rgvReportData.FilterDescriptors.Add(this.customFilterDescriptor); } return this.customFilterDescriptor; }}for the RadGridview
<telerik:RadGridView IsBusy="True" ElementExporting="RadGridView1_ElementExporting" telerikGridViewHeaderMenu:GridViewHeaderMenu.IsEnabled="True" telerikControls:StyleManager.Theme="Office_Blue" FrozenColumnCount="{Binding Value, ElementName=sldFreezeColumn, Mode=TwoWay}" IsReadOnly="True" AutoExpandGroups="True" x:Name="rgvReportData" AutoGenerateColumns="True" GroupPanelForeground="Black" Background="White" Loaded="DataGridLoaded" BorderThickness="1" Height="420"> <telerik:RadGridView.GroupPanelBackground> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFDFDFDF" Offset="1"/> <GradientStop Color="White"/> </LinearGradientBrush> </telerik:RadGridView.GroupPanelBackground> </telerik:RadGridView>and for the search Area
<TextBox x:Name="txtSearch" TextChanged="FilterValue_TextChanged" HorizontalAlignment="Left" ToolTipService.ToolTip="Search" TextWrapping="Wrap" Height="25" FontSize="12" Width="150" VerticalAlignment="Center" BorderBrush="#FFB8B8B8"/>Hoping for your response,
Aubrey :')