I am using Telerik version Q3 2013. I want to use my custom control instead of RadDateTimePicker control according to this post in row filter mode in Gridview. My Gridview columns are dynamic. Please provide with the source code so that I can apply this change as I want.
12 Answers, 1 is accepted
The other approach would be to modify the existing editor as explained in the Customize the Default Field Filter Editor article. How does this work for you?
Regards,
Didie
Telerik
Please help me with a sample project.
The e.Editor is a ReadOnly property and it cannot be replaced when the FieldFilterEditorCreated is raised. I am afraid you will have to override the CreateFieldFilterEditor method creating a custom column.
Regards,
Didie
Telerik
The code I can suggest is the one from the Create a Custom Field Filter Editor article. You should create a custom column and override the CreateFieldFilterEditor method.
Regards,
Didie
Telerik
Hi
I have created custom column with overriden CreateFieldFilterEditor method.
01.public class SalusGridViewAgendaItemDataColumn : GridViewDataColumn02. {03. public override FrameworkElement CreateFieldFilterEditor()04. {05. var filterControl = new SalusAgendaItemTypeFilterControl();06. 07. // This binding will transfer the significant property of your editor to the filtering view model.08. Binding selectedValueBinding = new Binding("Value");09. selectedValueBinding.Mode = BindingMode.TwoWay;10. selectedValueBinding.FallbackValue = null;11. selectedValueBinding.Converter = new AgendaItemTypeFilterEditorConverter();12. 13. var dc = DataContext;14. filterControl.SetBinding(SalusAgendaItemTypeFilterControl.SelectedAgendaItemTypeProperty, selectedValueBinding);15. 16. return filterControl;17. }18. }
But the suggested binding fails, because viewmodel does not contains property Value. DataContext of custom SalusGridViewAgendaItemDataColumn is my custom viewmodel (viewmodel of whole gridview) not yours viewmodel as described in documentation.
Any suggestions? Thanks Petr.
I answer myself.
My problem is soled by using custom filtering conrol instead of defining custom column type.
<telerik:GridViewDataColumn.FilteringControl> <agenda:SalusAgendaItemTypeFilteringControl/></telerik:GridViewDataColumn.FilteringControl>But why binding not works when using custom grid view data column?
Can you provide the code of your SalusAgendaItemTypeFilterControl as well as the AgendaItemTypeFilterEditorConverter so that we can examine it and give you a possible explanation why the binding is not working? Otherwise, it would just be guessing.
Regards,
Dilyan Traykov
Telerik
Hi, thanks for reply.
01.<UserControl x:Class="Prodware.Salus.Client.Modules.AgendaModule.Controls.SalusAgendaItemTypeFilteringControl"03. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"04. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"05. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 06. mc:Ignorable="d">07. <Grid x:Name="RootLayout"> 08. <ListBox Margin="5" Grid.Column="0" Grid.Row="1"09. ItemsSource="{Binding AgendaItemTypes}" SelectedItem="{Binding SelectedAgendaItemType}"/>10. </Grid>11.<UserControl>
01.public partial class SalusAgendaItemTypeFilteringControl : SalusUserControl, IFilteringControl02. {03. private GridViewDataControl _parentGrid;04. 05. public SalusAgendaItemTypeFilteringControl()06. {07. InitializeComponent();08. 09. RootLayout.DataContext = this;10. 11. AgendaItemTypes = Enum.GetValues(typeof (AgendaActivityType)).Cast<AgendaActivityType>();12. }13. 14. public void Prepare(GridViewColumn columnToPrepare)15. {16. _parentGrid = columnToPrepare.DataControl;17. }18. 19. public bool IsActive { get; set; }20. 21. public static readonly DependencyProperty AgendaItemTypesProperty = DependencyProperty.Register(22. "AgendaItemTypes", typeof(IEnumerable<AgendaActivityType>), typeof(SalusAgendaItemTypeFilteringControl), new FrameworkPropertyMetadata(default(IEnumerable<AgendaActivityType>)));23. 24. public IEnumerable<AgendaActivityType> AgendaItemTypes25. {26. get { return (IEnumerable<AgendaActivityType>)GetValue(AgendaItemTypesProperty); }27. set { SetValue(AgendaItemTypesProperty, value); }28. }29. 30. public static readonly DependencyProperty SelectedAgendaItemTypeProperty = DependencyProperty.Register(31. "SelectedAgendaItemType", typeof (AgendaActivityType), typeof (SalusAgendaItemTypeFilteringControl), new FrameworkPropertyMetadata(default(AgendaActivityType)));32. 33. public AgendaActivityType SelectedAgendaItemType34. {35. get { return (AgendaActivityType) GetValue(SelectedAgendaItemTypeProperty); }36. set { SetValue(SelectedAgendaItemTypeProperty, value); }37. }38. }
01.public class AgendaItemTypeFilterEditorConverter : IValueConverter02. {03. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)04. {05. if (Object.Equals(value, Telerik.Windows.Data.FilterDescriptor.UnsetValue))06. {07. // When the filter is turned off this is what your editor will get.08. return null;09. }10. 11. return value;12. }13. 14. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)15. {16. if (value == null)17. {18. // When your editor want to turn off the filter this is what it should return.19. return Telerik.Windows.Data.FilterDescriptor.UnsetValue;20. }21. 22. return value;23. }24. }Can you please have a look at the attached project and let me know if it produces the desired behaviour?
All I've changed is the FallbackValue of the binding for the custom column. I've switched that from null to AgendaActivityType.FreeTime. You can either remove it as a whole or provide a valid value from your AgendaActivityType enumeration.
Regards,
Dilyan Traykov
Telerik
Thanks for reply. Yes this works. But defining custom column with filtering control not solves my problem because I want to display fully customizable filtering control. My custom filter control is wrapped in telerik filtering control.
I have decided to use another way how to define fully customizable filtering control but still with no luck.
I've provided an answer to your other thread. Please take a look.
Regards,
Dilyan Traykov
Telerik