This is a migrated thread and some comments may be shown as answers.

Type of Columns

6 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 15 Feb 2012, 04:31 PM
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

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 15 Feb 2012, 04:40 PM
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 >>
0
Frank
Top achievements
Rank 1
answered on 15 Feb 2012, 04:49 PM
I tried this way, but i get the value null. Im using Q2 SP1.

0
Dimitrina
Telerik team
answered on 15 Feb 2012, 04:54 PM
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 >>
0
Frank
Top achievements
Rank 1
answered on 15 Feb 2012, 05:00 PM

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;
                }
            }
        }
    }
}
0
Accepted
Dimitrina
Telerik team
answered on 16 Feb 2012, 09:00 AM
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 >>
0
Frank
Top achievements
Rank 1
answered on 16 Feb 2012, 03:16 PM
Thank you very much, it works :)
Tags
GridView
Asked by
Frank
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Frank
Top achievements
Rank 1
Share this question
or