Type of Columns

7 posts, 1 answers
  1. Frank
    Frank avatar
    27 posts
    Member since:
    May 2011

    Posted 15 Feb 2012 Link to this post

    Hello,

    how can I find out the Type of the columns? Im going to set the default value of Filteroperator to "Contains" only for the columns with the type string.

    Thanks
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Feb 2012 Link to this post

    Hi,

    You can use the DataType property of the column currently being filtered.

    Regards,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Frank
    Frank avatar
    27 posts
    Member since:
    May 2011

    Posted 15 Feb 2012 Link to this post

    I tried this way, but i get the value null. Im using Q2 SP1.

  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Feb 2012 Link to this post

    Hello,

     Would you please share how do you set default value of FilterOperator to "Contains" ? 

    Greetings,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. Frank
    Frank avatar
    27 posts
    Member since:
    May 2011

    Posted 15 Feb 2012 Link to this post

    It seems like this example on teleriks forum:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Telerik.Windows.Data;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.GridView;
       
    namespace ChangeDefaultFilterOperator
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
       
                var nameColumn = (GridViewBoundColumnBase)this.clubsGrid.Columns[0];
                var customFilteringControl = new MyFilteringControl();
                nameColumn.FilteringControl = customFilteringControl;
            }
        }
           
      
        public class MyFilteringControl : FilteringControl
        {
            public override void Prepare(GridViewBoundColumnBase column)
            {
                base.Prepare(column);
        
                var vm = this.DataContext as FilteringViewModel;
                    
                if (vm != null)
                {
                    if (!vm.Filter1.IsActive)
                    {
                        vm.Filter1.Operator = FilterOperator.Contains;
                    }
                        
                    if (!vm.Filter2.IsActive)
                    {
                        vm.Filter2.Operator = FilterOperator.Contains;
                    }
                }
            }
        }
    }
  6. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 Feb 2012 Link to this post

    Hello,

    Have you tried this:

    public override void Prepare(GridViewBoundColumnBase column)
            {
                base.Prepare(column);
     
                var vm = this.DataContext as FilteringViewModel;
     
                if (vm != null)
                {
                    if (column != null && column.DataType == typeof(string))
                    {
                        if (!vm.Filter1.IsActive)
                        {
                            vm.Filter1.Operator = FilterOperator.Contains;
                        }
     
                        if (!vm.Filter2.IsActive)
                        {
                            vm.Filter2.Operator = FilterOperator.Contains;
                        }
                    }
                }

    I have tested using that code and it was working fine.
    Regards,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Frank
    Frank avatar
    27 posts
    Member since:
    May 2011

    Posted 16 Feb 2012 Link to this post

    Thank you very much, it works :)
Back to Top