CompositeFilterDescriptor

14 posts, 1 answers
  1. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 28 Jul 2014 Link to this post

    Hello Telerik
    today I saw CompositeFilterDescriptor in radgridview it is very amazing ,I have a question a bout it ,I want to use it in GridViewMultiComboBoxColumn so I wrote this code

    private void GrdItm_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
            {
               if (GrdItm.CurrentColumn is GridViewMultiComboBoxColumn)
                {
                    if (!isColumnAdded)
                    {
                        isColumnAdded = true;
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)GrdItm.ActiveEditor;

                        CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
                        compositeFilter.FilterDescriptors.Add(new FilterDescriptor("Title", FilterOperator.Contains, string.Empty));
                        editor.AutoFilter = true;
                   
                    }
    editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                  }
              }

      void EditorControl_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
            {
            
                    
                    if (e.NewItems == null || e.NewItems.Count == 0 )//|| e.NewItems[0] is FilterDescriptor)
                    {
                        return;
                    }
                    RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)GrdItm.ActiveEditor;
                    editor.EditorControl.FilterChanged -= new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                    CompositeFilterDescriptor MainCompos=e.NewItems[0] as CompositeFilterDescriptor;
                    if (MainCompos.FilterDescriptors.Count > 0)
                    {

                        FilterDescriptor desc = MainCompos.FilterDescriptors[0] as FilterDescriptor;

                        if (desc != null && desc.Operator == FilterOperator.Contains && desc.Value != null)
                        {
                            editor.EditorControl.FilterDescriptors.Clear();
                            string[] values = (desc.Value as string).Split();
                            CompositeFilterDescriptor compositeDescriptor = new CompositeFilterDescriptor();
                            compositeDescriptor.LogicalOperator = FilterLogicalOperator.And;
                            for (int i = 0; i < values.Length; i++)
                            {
                                FilterDescriptor newDescriptor = new FilterDescriptor(desc.PropertyName, desc.Operator, values[i]);
                                compositeDescriptor.FilterDescriptors.Add(newDescriptor);
                            }

                            editor.EditorControl.FilterDescriptors.Add(compositeDescriptor);
                        }
                    }
                    editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
           
            }

    now I need to Know is that a correct way or is there a better way to do this kind of filtering on GridViewMultiComboBoxColumn?
    I am waitting eagerly for your response.
  2. Dimitar
    Admin
    Dimitar avatar
    2742 posts

    Posted 31 Jul 2014 Link to this post

    Hello Mah,

    Thank you for writing.

    I am not sure what is the exact functionality that you want to achieve. I am confused because in this case you are creating a composite filter descriptor but is is not added to the grid. In addition just setting the AutoFilter property to true will not enable this functionality, you also need to add a filter descriptor:
    editor.AutoFilter = true;

    FilterDescriptor filter = new FilterDescriptor();
    filter.PropertyName = this.radMultiColumnComboBox1.DisplayMember;
    filter.Operator = FilterOperator.Contains;
    editor.EditorControl.FilterDescriptors.Add(filter);

    This way when you type directly in the editor's text box the drop down will be filtered according to the text that is entered.

    May I please ask you to specify your exact goals and describe your case a bit more, so I will be able to give you better recommendations.

    I hope this helps.

    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 01 Aug 2014 in reply to Dimitar Link to this post

    Thank you Dimitar  for the response,
    I have a gridview(name is GrdItm) that have several columns one of them is GridViewMultiComboBoxColumn
    I dont want to use CompositeFilterDescriptor for the "GrdItm"  I want to have such filter for the GridViewMultiComboBoxColumn on editng mode
  4. Dimitar
    Admin
    Dimitar avatar
    2742 posts

    Posted 05 Aug 2014 Link to this post

    Hello Mah,

    Thank you for writing back.

    I have attached a small sample project which contains a grid with a single GridViewMultiComboBoxColumn. The underlying grid in the editor's dropdown is filtered by a composite filter. Could you please check it and let me know how it fits in your case?

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  5. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 06 Aug 2014 in reply to Dimitar Link to this post

    Hello Dimitar
    Thank you for the sample .I saw your sample and add a form ("Form2") to it which shows what I exactly need
    ----------------------------------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
    using Telerik.WinControls.Data;
    using Telerik.WinControls;

    namespace _843790
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }

            private void Form2_Load(object sender, EventArgs e)
            {



                GridViewMultiComboBoxColumn col = new GridViewMultiComboBoxColumn();
                col.Name = Name;

                col.DataSource = GetTable1();
                col.AllowFiltering = true;

                col.DropDownStyle = RadDropDownStyle.DropDown;
                col.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                col.DisplayMember = "Name";
                col.ValueMember = "Name";
                col.FieldName = "Name";
                col.HeaderText = "Custom";
                col.Width = 400;
                radGridView1.Columns.Add(col);

                radGridView1.Columns[Name].Width = 400;
                radGridView1.Columns[Name].HeaderText = "Custom";
                radGridView1.Columns[Name].ReadOnly = false;
                radGridView1.Columns[Name].IsVisible = Visible;

                radGridView1.DataSource = GetTable();
                radGridView1.AllowEditRow = true;
                radGridView1.AllowAddNewRow = false;
                radGridView1.AllowDeleteRow = false;
                radGridView1.ReadOnly = false;

        
                radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
            }
            static DataTable GetTable1()
            {
                DataTable table = new DataTable();

                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("ID", typeof(int));


                table.Rows.Add("Rad Application Menu", 1);
                table.Rows.Add("Rad Application Menu Bottom Strip Layout", 2);
                table.Rows.Add("Rad Application Menu Button Element", 3);
                table.Rows.Add("Rad Application Menu Button Element Accessible Object", 4);
                table.Rows.Add("Rad Application Menu DropDown", 5);
                table.Rows.Add("Rad Application Menu Drop Down Element", 6);
                table.Rows.Add("Rad Arrow Button Element", 7);
                table.Rows.Add("Rad Button", 8);
                table.Rows.Add("Rad Button Accessible Object", 9);
                table.Rows.Add("Rad Button Base", 10);
                table.Rows.Add("Rad Button Element", 11);
                table.Rows.Add("Rad Calculator Arrow Button Element", 12);
                table.Rows.Add("Rad Calculator Editor", 13);
                table.Rows.Add("Rad GridView", 14);
                table.Rows.Add("Rad Lable", 15);
                table.Rows.Add("Rad MaskEditBox", 16);
                table.Rows.Add("Rad TreeView", 17);
                table.Rows.Add("Rad Dock", 18);
                table.Rows.Add("Rad RibbonBar", 19);
                table.Rows.Add("Rad TextBox", 20);

                return table;
            }

            static DataTable GetTable()
            {
               
                DataTable table = new DataTable();
                table.Columns.Add("Dosage", typeof(int));
                table.Columns.Add("Drug", typeof(string));
                table.Columns.Add("Name", typeof(string));
          

              
                DataRow dr1 = table.NewRow();
                dr1["Dosage"] = 25;
                dr1["Drug"] = "Indocin";
                dr1["Name"] = "Rad Button Base";
                table.Rows.Add(dr1);

                DataRow dr = table.NewRow();
                dr["Dosage"] = 50;
                dr["Drug"] = "Enebrel";
                dr["Name"] = "Rad Calculator Editor";
                table.Rows.Add(dr);

                return table;
            }

            bool isColumnAdded;//Only be made once the editor
            private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
            {
                if (radGridView1.CurrentColumn is GridViewMultiComboBoxColumn)
                {
                    if (!isColumnAdded)
                    {
                        isColumnAdded = true;
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                        editor.KeyDown += new KeyEventHandler(keyElement);
                        editor.ValueChanged += new EventHandler(chengeElement);
                        editor.KeyPress += new KeyPressEventHandler(editor_KeyPress);

                        editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;

                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("ID"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Name"));
                        editor.EditorControl.Columns["ID"].IsVisible = false;
                        editor.EditorControl.Columns["Name"].HeaderText = "Custom";
                        editor.EditorControl.Columns["Name"].Width = 400;

                        editor.AutoSizeDropDownHeight = false;
                        editor.EditorControl.AllowEditRow = true;

                        //             
                        editor.EditorControl.BackColor = System.Drawing.SystemColors.ControlLightLight;
                        editor.EditorControl.Location = new System.Drawing.Point(4, 1);

                        editor.EditorControl.ReadOnly = false;
                        editor.EditorControl.Visible = true;

                        editor.EditorControl.EnableFiltering = true;
                        CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
                        compositeFilter.FilterDescriptors.Add(new FilterDescriptor("Name", FilterOperator.Contains, string.Empty));
                        editor.EditorControl.FilterDescriptors.Add(compositeFilter);
                        editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);

                        editor.EditorControl.TabIndex = 0;
                        editor.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
                        editor.DropDownWidth = 750;
                        editor.DropDownHeight = 350;

                    }
                    else
                    {
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;

                        if (editor.EditorControl != null)
                        {
                            editor.EditorControl.FilterDescriptors.Clear();
                            CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
                            compositeFilter.FilterDescriptors.Add(new FilterDescriptor("Name", FilterOperator.Contains, string.Empty));
                            editor.EditorControl.FilterDescriptors.Add(compositeFilter);

                            if (editor.EditorControl.Rows.Count != 1)
                            {
                                editor.EditorControl.CurrentRow = null;
                            }
                            else
                            {
                                radGridView1.CurrentCell.Value = editor.EditorControl.Rows[0].Cells["Name"].Value;
                            }
                            editor.DataSource = null;
                        }
                    }
                }
            }

            void EditorControl_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
            {
                //editor.EditorControl.FilterDescriptors.Add("TecNoMainRef", FilterOperator.Contains, string.Empty);
                //editor.EditorControl.CurrentColumn = editor.EditorControl.Columns["TecNoMainRef"];
                //editor.EditorControl.FilterDescriptors.Expression.ToUpperInvariant();
                //string a = e.NewItems[0].GetType().ToString();
                if (e.NewItems == null || e.NewItems.Count == 0)//|| e.NewItems[0] is FilterDescriptor)
                {
                    //string a = e.NewItems[0].GetType().ToString();
                    return;
                }
                RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                editor.EditorControl.FilterChanged -= new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                FilterDescriptor desc = e.NewItems[0] as FilterDescriptor;
                //if (MainCompos.FilterDescriptors.Count > 0)
                //{

                //FilterDescriptor desc = MainCompos.FilterDescriptors[0] as FilterDescriptor;

                if (desc != null && desc.Operator == FilterOperator.Contains && desc.Value != null)
                {
                    editor.EditorControl.FilterDescriptors.Clear();
                    string[] values = (desc.Value as string).Split();
                    CompositeFilterDescriptor compositeDescriptor = new CompositeFilterDescriptor();
                    compositeDescriptor.LogicalOperator = FilterLogicalOperator.And;
                    for (int i = 0; i < values.Length; i++)
                    {
                        FilterDescriptor newDescriptor = new FilterDescriptor(desc.PropertyName, desc.Operator, values[i]);
                        compositeDescriptor.FilterDescriptors.Add(newDescriptor);
                    }

                    editor.EditorControl.FilterDescriptors.Add(compositeDescriptor);
                }
                //}
                editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
            }

            private void keyElement(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Delete)
                {
                    ((RadMultiColumnComboBoxElement)sender).Text = "";
                    ((RadMultiColumnComboBoxElement)sender).Value = "";
                    radGridView1.CurrentRow.Cells[radGridView1.CurrentColumn.Name].Value = "0";
                }
            }

            private void chengeElement(object sender, EventArgs e)
            {
                if (radGridView1.CurrentColumn != null)
                {
                    try
                    {
                        if (radGridView1.ActiveEditor is RadMultiColumnComboBoxElement)
                        {
                            RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                            editor.ValueChanged -= new EventHandler(chengeElement);

                            try
                            {
                                GridViewRowInfo row = editor.EditorControl.CurrentRow;
                                if (row != null)
                                {
                                    radGridView1.CurrentRow.Cells[radGridView1.CurrentColumn.Name].Value = row.Cells["Name"].Value;
                                }
                            }
                            catch { }

                            editor.ValueChanged += new EventHandler(chengeElement);
                        }
                    }
                    catch (Exception)
                    { }
                }
            }

            void editor_KeyPress(object sender, KeyPressEventArgs e)
            {
                if ((char.IsNumber(e.KeyChar)) || (char.IsLetter(e.KeyChar)))
                {
                    if (((RadMultiColumnComboBoxElement)sender).Text.Trim() == "")
                    {
                        e.Handled = true;

                        ((RadMultiColumnComboBoxElement)sender).Text = e.KeyChar.ToString();
                        ((RadMultiColumnComboBoxElement)sender).SelectionStart = 1;
                    }
                }
            }
        
        }
    }

    ------------------------------------------designer
    namespace _843790
    {
        partial class Form2
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            #region Windows Form Designer generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
                this.SuspendLayout();
                //
                // radGridView1
                //
                this.radGridView1.Location = new System.Drawing.Point(39, 32);
                this.radGridView1.Name = "radGridView1";
                this.radGridView1.Size = new System.Drawing.Size(697, 348);
                this.radGridView1.TabIndex = 0;
                this.radGridView1.Text = "radGridView1";
                //
                // Form2
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(776, 409);
                this.Controls.Add(this.radGridView1);
                this.Name = "Form2";
                this.Text = "Form2";
                this.Load += new System.EventHandler(this.Form2_Load);
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
                this.ResumeLayout(false);

            }

            #endregion

            private Telerik.WinControls.UI.RadGridView radGridView1;
        }
    }
    --------------------------------------

    .I send you a Picture (If it was possible  I would send you a video )in the picture for example I want to see all the items which contain 'Rad' and 'View'.
    I would be very thank full If you could tel me that
    the way which I choose for filtering is a right way or not or is there a better way to do this?
    I am Waiting eagerly for your response.
  6. Answer
    Dimitar
    Admin
    Dimitar avatar
    2742 posts

    Posted 08 Aug 2014 Link to this post

    Hello Mah,

    Thank you for writing back.

    If I understand correctly you want to type "Rad" and "View" and display all items that contain both words. In this case it would be better if you use a custom filtering. I have recreated the example in order to implement such functionality (to test start the project and type "Rad View" in one of the editors). Could you please check it and let me know how it fits in your case?

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 09 Aug 2014 in reply to Dimitar Link to this post

    Thank you Dimitar
    Your solution really help me,and it works.Now I have another question in the sample when I enter a cell
    (the cell has value ) the text value will disappear and when I leave the cell the text value will show again,
    Is there any way to see the text value when I enter the cell ?
  8. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 11 Aug 2014 in reply to mah Link to this post

    Hello Dimitar
    In the sample project that you have sent ,I increase number of rows of datattable "table" to 6000 rows,
    now when I start  typing in the, it  filters very slowly,Is it possible to  use CompositeFilterDescriptor in   EditorControl_FilterChanged()
    instead of EditorControl_CustomFiltering()  because it has better speed than custom filtering.
    if it is possible I will be very thank full if you could send me a sample.


      void EditorControl_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
            {
                //editor.EditorControl.FilterDescriptors.Add("TecNoMainRef", FilterOperator.Contains, string.Empty);
                //editor.EditorControl.CurrentColumn = editor.EditorControl.Columns["TecNoMainRef"];
                //editor.EditorControl.FilterDescriptors.Expression.ToUpperInvariant();
                //string a = e.NewItems[0].GetType().ToString();
                if (e.NewItems == null || e.NewItems.Count == 0)//|| e.NewItems[0] is FilterDescriptor)
                {
                    //string a = e.NewItems[0].GetType().ToString();
                    return;
                }
                RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                editor.EditorControl.FilterChanged -= new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                FilterDescriptor desc = e.NewItems[0] as FilterDescriptor;
                //if (MainCompos.FilterDescriptors.Count > 0)
                //{

                //FilterDescriptor desc = MainCompos.FilterDescriptors[0] as FilterDescriptor;

                if (desc != null && desc.Operator == FilterOperator.Contains && desc.Value != null)
                {
                    editor.EditorControl.FilterDescriptors.Clear();
                    string[] values = (desc.Value as string).Split();
                    CompositeFilterDescriptor compositeDescriptor = new CompositeFilterDescriptor();
                    compositeDescriptor.LogicalOperator = FilterLogicalOperator.And;
                    for (int i = 0; i < values.Length; i++)
                    {
                        FilterDescriptor newDescriptor = new FilterDescriptor(desc.PropertyName, desc.Operator, values[i]);
                        compositeDescriptor.FilterDescriptors.Add(newDescriptor);
                    }

                    editor.EditorControl.FilterDescriptors.Add(compositeDescriptor);
                }
                //}
                editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
            }
  9. Dimitar
    Admin
    Dimitar avatar
    2742 posts

    Posted 12 Aug 2014 Link to this post

    Hi Mah,

    Thank you for writing back.

    Please find attached sample project where the default filter is removed and a composite one is constructed instead. 

    I hope this helps.

    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  10. Roya
    Roya avatar
    26 posts
    Member since:
    Jan 2012

    Posted 12 Aug 2014 in reply to Dimitar Link to this post

    Thank you Dimitar
    I worked hours and hours on filtering in radmulticolumncombobox and I used few ways to have a desire
    filtering (I think it is interesting to other developers to see it) . is it possible to send you a sample and a video to show what I do?
  11. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 13 Aug 2014 in reply to Dimitar Link to this post

    Hello Dimater I saw the sample and get idea from it ,the editor of my gridviewcombobox has 5 columns
    (Id,Code,Name,StockQty,Active) I needed an interactive filterng, If you click on the Colmn "Code" of the
    editor you can do filtering  by code,If you click on column "Name" you can do filtering by Name and if you click on column "StockQty" you can do filtering by StockQty ,the code below shows what .if it is possible
    have look at on my code and if there is a problem ,I will be very thankfull to tel me the problem
    ----------------------------------------------------------------------------------------------------------------------------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
    using Telerik.WinControls.Data;
    using Telerik.WinControls;

    namespace _843790
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            string StrFilter = "";
            DataTable table = new DataTable();
            private void Form2_Load(object sender, EventArgs e)
            {



                GridViewMultiComboBoxColumn col = new GridViewMultiComboBoxColumn();
                col.Name = "Custom";
                GetTable1();
                col.DataSource = table;
                col.AllowFiltering = true;

                col.DropDownStyle = RadDropDownStyle.DropDown;
                col.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                col.DisplayMember = "Name";
                col.ValueMember = "ID";
                col.FieldName = "Name";
                col.HeaderText = "Custom";
               
                col.Width = 400;
                radGridView1.Columns.Add(col);

                radGridView1.Columns["Custom"].Width = 400;
                radGridView1.Columns["Custom"].HeaderText = "Custom";
                radGridView1.Columns["Custom"].ReadOnly = false;
                radGridView1.Columns["Custom"].IsVisible = Visible;

                radGridView1.DataSource = GetTable();
                radGridView1.AllowEditRow = true;
                radGridView1.AllowAddNewRow = false;
                radGridView1.AllowDeleteRow = false;
                radGridView1.ReadOnly = false;

        
                radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
            }
            void  GetTable1()
            {
               

                table.Columns.Add("ID", typeof(int));
                table.Columns.Add("Code", typeof(string));
                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("StockQty", typeof(decimal));
                table.Columns.Add("Active", typeof(bool));
                


                table.Rows.Add(1,  "0001","Rad Application Menu", 10,false);
                table.Rows.Add(2,  "0002", "Rad Application Menu Bottom Strip Layout", 20,true);
                table.Rows.Add(3, "0003", "Rad Application Menu Button Element", 30, false);
                table.Rows.Add(4, "0004", "Rad Application Menu Button Element Accessible Object", 40, true);
                table.Rows.Add(5, "0005", "Rad Application Menu DropDown", 50, false);
                table.Rows.Add(6, "0006", "Rad Application Menu Drop Down Element", 60, true);
                table.Rows.Add(7, "0007", "Rad Arrow Button Element", 70, false);
                table.Rows.Add(8, "0008", "Rad Button", 80, true);
                table.Rows.Add(9,  "0009", "Rad Button Accessible Object", 90);
                table.Rows.Add(10, "0010", "Rad Button Base", 100, true);
                table.Rows.Add(11, "0011", "Rad Button Element", 110, false);
                table.Rows.Add(12, "0012", "Rad Calculator Arrow Button Element", 120, true);
                table.Rows.Add(13, "0013", "Rad Calculator Editor", 130, false);
                table.Rows.Add(14, "0014", "Rad GridView", 140, true);
                table.Rows.Add(15, "0015", "Rad Lable", 150, false);
                table.Rows.Add(16, "0016", "Rad MaskEditBox", 160, true);
                table.Rows.Add(17, "0017", "Rad TreeView", 170, false);
                table.Rows.Add(18, "0018", "Rad Dock", 180, true);
                table.Rows.Add(19, "0019", "Rad RibbonBar", 190);
                table.Rows.Add(20, "0020", "Rad TextBox", 200, true);
                int RowCount=table.Rows.Count;
                int maxid=21;
                decimal StockQty =0;
                bool Active = false;
                for (int j = 0; j < 300; j++)
                {
                    for (int i = 0; i < RowCount; i++)
                    {
                         decimal.TryParse(table.Rows[i]["StockQty"].ToString(), out  StockQty);
                         Active = (i % 2 == 0 ? true : false);
                         table.Rows.Add(maxid, table.Rows[i]["Code"], table.Rows[i]["Name"], StockQty * i, Active);
                        maxid++;
                    }
                }
               
            }

            static DataTable GetTable()
            {
               
                DataTable table = new DataTable();
                table.Columns.Add("Dosage", typeof(int));
                table.Columns.Add("Drug", typeof(string));
                table.Columns.Add("Name", typeof(string));
          

              
                DataRow dr1 = table.NewRow();
                dr1["Dosage"] = 25;
                dr1["Drug"] = "Indocin";
                dr1["Name"] = "Rad Button Base";
                table.Rows.Add(dr1);

                DataRow dr = table.NewRow();
                dr["Dosage"] = 50;
                dr["Drug"] = "Enebrel";
                dr["Name"] = "Rad Calculator Editor";
                table.Rows.Add(dr);

                return table;
            }

            bool isColumnAdded;//Only be made once the editor
            private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
            {
                if (radGridView1.CurrentColumn is GridViewMultiComboBoxColumn)
                {
                    if (!isColumnAdded)
                    {
                        isColumnAdded = true;
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                        //editor.KeyDown += new KeyEventHandler(keyElement);
                        //editor.ValueChanged += new EventHandler(chengeElement);
                        //editor.KeyPress += new KeyPressEventHandler(editor_KeyPress);

                        editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;

                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("ID"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Code"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Name"));
                        editor.EditorControl.Columns.Add(new GridViewDecimalColumn("StockQty"));

                        editor.EditorControl.Columns["ID"].IsVisible = false;
                        editor.EditorControl.Columns["Name"].HeaderText = "Name";
                        editor.EditorControl.Columns["Code"].HeaderText = "Code";
                        editor.EditorControl.Columns["StockQty"].HeaderText = "StockQty";
                        editor.EditorControl.Columns["Name"].Width = 400;
                        editor.EditorControl.Columns["StockQty"].Width = 200;

                        editor.AutoSizeDropDownHeight = false;
                        editor.EditorControl.AllowEditRow = false;

                        //             
                        editor.EditorControl.BackColor = System.Drawing.SystemColors.ControlLightLight;
                        editor.EditorControl.Location = new System.Drawing.Point(4, 1);

                        editor.EditorControl.ReadOnly = false;
                        editor.EditorControl.Visible = true;

                        editor.EditorControl.EnableFiltering = true;
                        StrFilter = "Name";

                        editor.EditorControl.FilterDescriptors.Clear();
                        CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();

                        if (editor.EditorControl.CurrentColumn != null && editor.EditorControl.CurrentColumn.GetType() == typeof(GridViewDecimalColumn))
                        {
                            compositeFilter.FilterDescriptors.Add(new FilterDescriptor((StrFilter == "" ? "Name" : StrFilter), FilterOperator.StartsWith, string.Empty));

                        }
                        else
                        {
                            compositeFilter.FilterDescriptors.Add(new FilterDescriptor((StrFilter == "" ? "Name" : StrFilter), FilterOperator.Contains, string.Empty));
                        }

                        editor.EditorControl.FilterDescriptors.Add(compositeFilter);

                        editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                        editor.EditorControl.CellClick += new GridViewCellEventHandler(EditorControl_CellClick);

                        editor.EditorControl.TabIndex = 0;
                        editor.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
                        editor.DropDownWidth = 750;
                        editor.DropDownHeight = 350;
                        

                    }
                    else
                    {
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;

                        if (editor.EditorControl != null)
                        {
                            
                                radGridView1.CurrentCell.Value = editor.EditorControl.Rows[0].Cells["Id"].Value;
                           
                            editor.DataSource = null;
                        }
                    }
                }
            }

            void EditorControl_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
            {
                if (e.NewItems == null || e.NewItems.Count == 0)//|| e.NewItems[0] is FilterDescriptor)
                {

                    return;
                }
                RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                editor.EditorControl.FilterChanged -= new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                FilterDescriptor desc = e.NewItems[0] as FilterDescriptor;
                FilterOperator Opr = desc.Operator;

                if (desc != null && desc.Value != null)
                {
                    CompositeFilterDescriptor compositeDescriptor = new CompositeFilterDescriptor();
                    editor.EditorControl.FilterDescriptors.Clear();
                    string FilterColumn = "";
                    
                    if (radGridView1.CurrentColumn.Name == "Custom")
                    {
                        FilterColumn = (StrFilter == "" ? "Name" : StrFilter);
                    }
                    if (editor.EditorControl.CurrentColumn.GetType() == typeof(GridViewDecimalColumn))
                    {
                        desc.Operator = FilterOperator.IsEqualTo;
                        compositeDescriptor.Operator = FilterOperator.IsEqualTo;
                        FilterDescriptor newDescriptor = new FilterDescriptor(FilterColumn, desc.Operator, desc.Value);
                        compositeDescriptor.FilterDescriptors.Add(newDescriptor);
                    }
                    else
                    {
                        desc.Operator = FilterOperator.Contains;
                        compositeDescriptor.Operator = FilterOperator.Contains;
                        string[] values = (desc.Value as string).Split();
                        compositeDescriptor.LogicalOperator = FilterLogicalOperator.And;
                        for (int i = 0; i < values.Length; i++)
                        {
                            FilterDescriptor newDescriptor = new FilterDescriptor(FilterColumn, desc.Operator, values[i]);
                            compositeDescriptor.FilterDescriptors.Add(newDescriptor);
                        }
                    }
                    editor.EditorControl.FilterDescriptors.Add(compositeDescriptor);
                }

                editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
            }
            void EditorControl_CellClick(object sender, GridViewCellEventArgs e)
            {
                try
                {
                    if (e.Row is GridViewTableHeaderRowInfo)
                    {
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
                        if (editor != null && editor.EditorControl != null)
                        {

                            editor.EditorControl.CurrentColumn = editor.EditorControl.Columns[e.Column.Name];

                            StrFilter = e.Column.Name;
                            
                            editor.EditorControl.FilterDescriptors.Clear();
                            CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
                            if (StrFilter != "" && editor.EditorControl.Columns[StrFilter].GetType() == typeof(GridViewDecimalColumn))
                            {
                                compositeFilter.FilterDescriptors.Add(new FilterDescriptor((StrFilter == "" ? "Name" : StrFilter), FilterOperator.IsEqualTo, null));

                            }
                            else
                            {
                                compositeFilter.FilterDescriptors.Add(new FilterDescriptor((StrFilter == "" ? "Name" : StrFilter), FilterOperator.Contains, string.Empty));
                            }
                            editor.EditorControl.FilterDescriptors.Add(compositeFilter);
                            //editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);


                        }
                    }
                }
                catch (Exception ex)
                {
                    
                }
            }

            private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            {
                if (radGridView1.CurrentColumn.Name.ToString() == "Custom")
                {
                    RadMultiColumnComboBoxElement editor = radGridView1.ActiveEditor as RadMultiColumnComboBoxElement;
                    if (editor != null)
                    {
                        //string CurrentText = editor.Text;
                        editor.EditorControl.CurrentRow = null;
                        editor.DisplayMember = "Name";
                        editor.ValueMember = "ID";
                        
                        DataRow[] dr;
                       

                        DataTable dt = new DataTable();

                        dr = null;
                        dr = table.Select("Active=1");
                        if (dr.Length > 0)
                        {
                            dt = dr.CopyToDataTable();
                        }
                        else
                        {
                            dt = table.Clone();
                        }

                        editor.DataSource = dt;
                        editor.EditorControl.FilterChanged -= new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
                        editor.EditorControl.FilterDescriptors.Clear();
                        CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
                        if (StrFilter != "" && editor.EditorControl.Columns[StrFilter].GetType() == typeof(GridViewDecimalColumn))
                        {
                            compositeFilter.FilterDescriptors.Add(new FilterDescriptor((StrFilter == "" ? "Name" : StrFilter), FilterOperator.IsEqualTo, null));

                        }
                        else
                        {
                            compositeFilter.FilterDescriptors.Add(new FilterDescriptor((StrFilter == "" ? "Name" : StrFilter), FilterOperator.Contains, string.Empty));
                        }
                        editor.EditorControl.FilterDescriptors.Add(compositeFilter);
                        editor.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);

                        if (editor.EditorControl.CurrentRow != null && editor.EditorControl.CurrentRow.Index >= 0)
                        {
                            editor.EditorControl.CurrentRow.IsCurrent = false;
                        }
                        editor.EditorControl.CurrentColumn = editor.EditorControl.Columns[(StrFilter == "" ? "Name" : StrFilter)];
                        //editor.Text = CurrentText;

                    }
                }
            }
           
        
        }
    }
    -----------------****************----------Designer
    namespace _843790
    {
        partial class Form2
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            #region Windows Form Designer generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).BeginInit();
                this.SuspendLayout();
                //
                // radGridView1
                //
                this.radGridView1.Location = new System.Drawing.Point(39, 32);
                this.radGridView1.Name = "radGridView1";
                this.radGridView1.Size = new System.Drawing.Size(697, 348);
                this.radGridView1.TabIndex = 0;
                this.radGridView1.Text = "radGridView1";
                this.radGridView1.CellEditorInitialized += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellEditorInitialized);
                //
                // Form2
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(776, 409);
                this.Controls.Add(this.radGridView1);
                this.Name = "Form2";
                this.Text = "Form2";
                this.Load += new System.EventHandler(this.Form2_Load);
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
                this.ResumeLayout(false);

            }

            #endregion

            private Telerik.WinControls.UI.RadGridView radGridView1;
        }
    }
  12. Dimitar
    Admin
    Dimitar avatar
    2742 posts

    Posted 15 Aug 2014 Link to this post

    Hello,

    @ Roya
    You cannot upload video or sample projects in the forum, you can only upload images and code snippets. If you have some interesting problem solution you have implemented and you are willing to share it with the community, you can use the Code Library section for the purpose. Here you can find more information on how to use it: http://www.telerik.com/support/code-library/instructions.

    @ Mah
    I have examined your code and I have tested the behavior and it looks ok to me. Nevertheless you should test this with all cases that apply to your scenario. As a suggestion you should avoid using such empty catch blocks since they cannot solve anything. 

    I hoape this helps.

    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  13. mah
    mah avatar
    7 posts
    Member since:
    Jul 2014

    Posted 16 Aug 2014 in reply to Dimitar Link to this post

    Thank you Dimitar
    Thank you for your patience to see my code, YOU ARE NUMBER ONE.
  14. Dimitar
    Admin
    Dimitar avatar
    2742 posts

    Posted 18 Aug 2014 Link to this post

    Hello Mah,

    Thank you for writing back.

    I am glad I could be of help. Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top