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

Multicolumncombox filtering in gridview

15 Answers 601 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Razeen
Top achievements
Rank 1
Razeen asked on 17 Apr 2010, 05:24 PM
Hi,

         I am trying to achieve filtering of multicolumn combobox inside the gridview..Can you give me an idea how to do it?

Thanks

15 Answers, 1 is accepted

Sort by
0
Razeen
Top achievements
Rank 1
answered on 19 Apr 2010, 09:57 AM
Hi

I am evaluating Radgrid for winforms..I am trying to add a multi combobox column and enable filtering on this multi combobox..For e.g..An Invoice.. i have many items in multicombo box..As i type item names first one or two letter it should filter and display those item only..Its working fine when we use independent Multi combo box column outside grid..But i am not able to make it inside..I checked ur documentation..But there is no information abt it..Please help me on this

Thanks & Regards
Razeen
0
Martin Vasilev
Telerik team
answered on 22 Apr 2010, 12:55 PM
Hi Razeen,

Thank you for writing.

If I understand you correctly, you want to implement AutoFilter functionality when editing a GridViewMultiComboBoxColumn. This can be achieved by setting the AutoFilter property to true and adding a filter expression for the multi-column combobox editor. Please, consider the following code:
 
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadMultiColumnComboBoxElement multiComboElement = this.radGridView1.ActiveEditor as RadMultiColumnComboBoxElement;
    if (multiComboElement != null)
    {
        multiComboElement.EditorControl.MasterGridViewTemplate.BestFitColumns();
        multiComboElement.DropDownStyle = RadDropDownStyle.DropDown;
        multiComboElement.AutoFilter = true;
        if (multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Count == 0)
        {
            FilterExpression autoFilter = new FilterExpression(multiComboElement.DisplayMember, FilterExpression.BinaryOperation.AND,
                GridKnownFunction.StartsWith, GridFilterCellElement.ParameterName);
            autoFilter.Parameters.Add(GridFilterCellElement.ParameterName, true);
            multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Add(autoFilter);
        }
    }
}

Let me know if you have any additional questions.

Best wishes,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Razeen
Top achievements
Rank 1
answered on 23 Apr 2010, 01:25 AM
Thanks for the reply telerik..It works fine except when i click the multicolumncombo box for the first time..it shows empty data..What maybe the problem?As soon i start type something it shows the curresponding items..working fine..Also on subsequent click of multicolumncombo box it shows the data..Problem is only when i click combo for the first time...

  One more question i would like to clear how can i get the selected row of the multicolumncombobox? For e.g when i select the multicombobox item in first row of radgrid,i want to get the values of that multicmobox column selected row and set it on other cells of first row of radgrid..Please check the attachement to get clear picture of my question

I am loading the multingcombo as follows
        private void frmRecievable_Load(object sender, EventArgs e)
        {
            string query = "select *.......";
            DataTable dtSupplier = new DataTable();
            dtSupplier = dal.LoadDataTable(query);
            GridViewMultiComboBoxColumn col = (GridViewMultiComboBoxColumn)radGridView1.MasterGridViewTemplate.Columns[0];
            col.DataSource = dtSupplier;
            col.DisplayMember = "Item_Name";
            col.ValueMember = "Item_Code";
            col.FieldName = "Item_Code";
            col.UniqueName = "Item_Code";
            col.HeaderText = "Item";
            col.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
            col.DropDownWidth = 1000;
        }

Thanks
0
Martin Vasilev
Telerik team
answered on 27 Apr 2010, 06:09 PM
Hi Razeen,

Thank you for getting back to me. Actually, I have a small mistake in my code, which leads to the undesired behavior on MultiColumnComboBox editor initialization. Please, change the adding parameters code as following:
 
//autoFilter.Parameters.Add(GridFilterCellElement.ParameterName, true);
autoFilter.Parameters.Add(GridFilterCellElement.ParameterName, "");

As to your second question, you can subscribe to SelectionChanged event and get the current row in the EditorControl:
 
multiComboElement.EditorControl.SelectionChanged += new EventHandler(EditorControl_SelectionChanged);
void EditorControl_SelectionChanged(object sender, EventArgs e)
{
    MultiColumnComboGridView mcv = (MultiColumnComboGridView)sender;
    GridViewRowInfo selectedRow = mcv.CurrentRow;
}

Do not hesitate to contact me again if you need additional assistance.

 
Regards,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Razeen
Top achievements
Rank 1
answered on 28 Apr 2010, 05:24 PM
Hi Martin,

Thanks for replying..Solution to the first question is perfectly allright now..But in second question you told to get the selected row by using mcv.CurrentRow..I am not getting the selected row..I get the following error


"Object reference not set to an instance of an object."


I got it work by using the following workaround.But it seems its not the correct way as its getting the value 2 times..Message box is showing two times.

void EditorControl_SelectionChanged(object sender, EventArgs e)
{
MultiColumnComboGridView mcv = (MultiColumnComboGridView)sender;
GridViewRowInfo selectedRow = mcv.CurrentRow;
if (mcv.SelectedRows.Count == 0)
{
}
else
{
string tt = mcv.SelectedRows[0].Cells["Item_Code"].Value.ToString();
MessageBox.Show(tt);

}
}


Also one more question..

I have Code,Item,category columns in multicolumncombox..and Item and Category column in radgrid.
I want to set the selected value(selected row's category column value) of multicomboboxcolumn in radgrids Category column as any item is selected from the multicolumncombo....I tried to do it in different ways..But not able to do it correctly.
0
Martin Vasilev
Telerik team
answered on 30 Apr 2010, 05:35 PM
Hello Razeen,

Actually, my previous code snippets were only for sample/example proposes and they do not have all of the needed code to make them complete, such as null reference checks for example. Please, consider the following code as a way to get the current row in the MultiColumnComboBox editor, take a particular cell value and save it in other grid cell in CellValueChanged event:
 
object _unitPrice;
void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    if (e.ColumnIndex == 5 && _unitPrice != null)
    {
        e.Row.Cells["UnitPrice"].Value = _unitPrice;
    }
    _unitPrice = null;
}
void EditorControl_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{            
    GridViewRowInfo selectedRow = e.CurrentRow;
    if (selectedRow != null)
    {
        _unitPrice = selectedRow.Cells["UnitPrice"].Value;
    }
    else
    {
        _unitPrice = null;
    }
}



Regards,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
shinu rag
Top achievements
Rank 1
answered on 17 May 2010, 06:14 AM
hii Martin Vasile.
i have some doubt that.. when i bindind big datas(25000 rows and above) in gridview multicolumn, its getting slow...

here my codes.......
// global declaration  
List<mast_tbl_Diagnosis> listdiagnosis;
GridViewMultiComboBoxColumn col_0;
GridViewMultiComboBoxColumn col_1;

 
private void CaseSheet_Load(object sender, EventArgs e) 
            // Form Load Event 
            col_0 = (GridViewMultiComboBoxColumn)GridCurrentProcedure.MasterGridViewTemplate.Columns[0]; 
            col_1 = (GridViewMultiComboBoxColumn)GridCurrentProcedure.MasterGridViewTemplate.Columns[1]; 
 
            listprocedure = objProcedureCodesData.SelectAll().Where(t1 => t1.Deleted == false).ToList(); 
 
            col_0.DataSource = listprocedure; 
            col_1.DataSource = listprocedure; 
 
 
            col_0.DisplayMember = "Proc_Code"
            col_0.ValueMember = "Proc_Code"
 
            col_1.DisplayMember = "Proc_Description"
            col_1.ValueMember = "Proc_Description";  
            col_0.DropDownStyle = col_1.DropDownStyle = RadDropDownStyle.DropDown;      
 
 
private void GridCurrentProcedure_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
        { 
           
            if (GridCurrentProcedure.ActiveEditor is RadMultiColumnComboBoxElement) 
            { 
 
                RadMultiColumnComboBoxElement multiColumnComboElement = (RadMultiColumnComboBoxElement)GridCurrentProcedure.ActiveEditor; 
                 
                multiColumnComboElement.AutoSizeDropDownToBestFit = true
                multiColumnComboElement.AutoFilter = true
                multiColumnComboElement.DropDownSizingMode = SizingMode.UpDownAndRightBottom; 
 
                if (multiColumnComboElement.Columns.Count > 0) 
                    return
 
 
                GridViewTextBoxColumn column = new GridViewTextBoxColumn("ID"); 
                column.HeaderText = "ID"
                column.IsVisible = false
                multiColumnComboElement.Columns.Add(column); 
 
 
                column = new GridViewTextBoxColumn("Proc_Code"); 
                column.HeaderText = "Proc_Code"
                multiColumnComboElement.Columns.Add(column); 
 
                column = new GridViewTextBoxColumn("Proc_Description"); 
                column.HeaderText = "Procedure Description"
                multiColumnComboElement.Columns.Add(column); 
 
                if (e.ColumnIndex == 0) 
                { 
                    multiColumnComboElement.SelectedIndexChanged += new EventHandler(ProcCode_multiColumnComboElement_SelectedIndexChanged); 
                } 
                else 
                    multiColumnComboElement.SelectedIndexChanged += new EventHandler(ProcDescription_multiColumnComboElement_SelectedIndexChanged); 
 
 
            } 
             
        } 
 
        private void GridCurrentProcedure_CellEditorInitialized(object sender, GridViewCellEventArgs e) 
        { 
            
            RadMultiColumnComboBoxElement multiComboElement = this.GridCurrentProcedure.ActiveEditor as RadMultiColumnComboBoxElement; 
            if (multiComboElement != null
            { 
                multiComboElement.EditorControl.MasterGridViewTemplate.BestFitColumns(); 
                multiComboElement.AutoFilter = true
 
                if (multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Count == 0) 
                { 
                    FilterExpression autoFilter = new FilterExpression("Proc_Code", FilterExpression.BinaryOperation.AND, 
                        GridKnownFunction.StartsWith, GridFilterCellElement.ParameterName); 
                    autoFilter.Parameters.Add(GridFilterCellElement.ParameterName, string.Empty); 
                    multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Add(autoFilter); 
 
                    autoFilter = new FilterExpression("Proc_Description", FilterExpression.BinaryOperation.AND, 
                          GridKnownFunction.StartsWith, GridFilterCellElement.ParameterName); 
                    autoFilter.Parameters.Add(GridFilterCellElement.ParameterName, string.Empty); 
                    multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Add(autoFilter); 
 
                } 
            } 
             
        } 
 
 
 void ProcCode_multiColumnComboElement_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            
            if (GridCurrentProcedure.ActiveEditor is RadMultiColumnComboBoxElement) 
            { 
                RadMultiColumnComboBoxElement multiColumnComboElement = (RadMultiColumnComboBoxElement)GridCurrentProcedure.ActiveEditor; 
 
                multiColumnComboElement.SelectedIndexChanged -= new EventHandler(ProcDescription_multiColumnComboElement_SelectedIndexChanged); 
 
                try 
                { 
                    GridViewRowInfo row = multiColumnComboElement.EditorControl.CurrentRow; 
                    if (row != null
                    { 
                        GridCurrentProcedure.CurrentRow.Cells[1].Value = row.Cells[2].Value; 
                        GridCurrentProcedure.CurrentRow.Cells[2].Value = row.Cells[0].Value; 
                    } 
                } 
                catch { } 
 
                multiColumnComboElement.SelectedIndexChanged += new EventHandler(ProcDescription_multiColumnComboElement_SelectedIndexChanged); 
            } 
        } 
        void ProcDescription_multiColumnComboElement_SelectedIndexChanged(object sender, EventArgs arg) 
        { 
            if (GridCurrentProcedure.ActiveEditor is RadMultiColumnComboBoxElement) 
            { 
                RadMultiColumnComboBoxElement multiColumnComboElement = (RadMultiColumnComboBoxElement)GridCurrentProcedure.ActiveEditor; 
                multiColumnComboElement.SelectedIndexChanged -= new EventHandler(ProcCode_multiColumnComboElement_SelectedIndexChanged); 
 
                try 
                { 
                    GridViewRowInfo row = multiColumnComboElement.EditorControl.CurrentRow; 
                    if (row != null
                    { 
                        GridCurrentProcedure.CurrentRow.Cells[0].Value = row.Cells[1].Value; 
                        GridCurrentProcedure.CurrentRow.Cells[2].Value = row.Cells[0].Value; 
                    } 
                } 
                catch { } 
 
                multiColumnComboElement.SelectedIndexChanged += new EventHandler(ProcCode_multiColumnComboElement_SelectedIndexChanged); 
            } 
        } 
 
 

when i click on the gridview multicolumn combo box its take more time to drop down...
is there any way to make it fast.
Thanks
0
Martin Vasilev
Telerik team
answered on 20 May 2010, 09:50 AM
Hello shinu rag,

I have tested scenario with 25,000 records and I have to admit that there is some performance slow-down when using MultiColumnComboBoxColumn. Unfortunately, there is not much that could be done in this situation. Currently we are working on a new version of RadGridView and we will consider some optimization in drop-down columns to allow using thousands records.

Greetings,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
shinu rag
Top achievements
Rank 1
answered on 20 May 2010, 10:04 AM
ok thank you martin
0
Tajes
Top achievements
Rank 1
answered on 02 Dec 2010, 04:05 PM
Hello Martin Vasilev,
     I'm also trying to use filtering in the GridViewMultiComboBoxColumn. I'm using Telerik Winforms Q3 2010 controls. I used your code but some properties are marked Obsoleted. I changed it for the new properties.
    My problem is I can not write in the combobox of the grid when edit mode is begun. I can only select in drop down list. Is there other way to do it now with Q3 2010?

Thanks in advance and sorry for my English.
0
Martin Vasilev
Telerik team
answered on 07 Dec 2010, 01:52 PM
Hello Iván Tajes,

Thank you for contacting us.

Actually, we have done some improvements concerning the autofilter functionality for MultiColumnComboBox column since my previous answers in this thread. Please try the following code, it should work as expected: 
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadMultiColumnComboBoxElement multiComboElement = this.radGridView1.ActiveEditor as RadMultiColumnComboBoxElement;
    if (multiComboElement != null)
    {
        multiComboElement.EditorControl.MasterTemplate.BestFitColumns();
        multiComboElement.DropDownStyle = RadDropDownStyle.DropDown;
        multiComboElement.AutoFilter = true;
        if (multiComboElement.EditorControl.FilterDescriptors.Count == 0)
        {
            multiComboElement.EditorControl.FilterDescriptors.Add(multiComboElement.DisplayMember, FilterOperator.StartsWith, String.Empty);
        }
    }
}

Let me know if you have any additional questions.

Greetings,
Martin Vasilev
the Telerik team
Get started with RadControls for WinForms with numerous videos and detailed documentation.
0
Rajesh
Top achievements
Rank 1
answered on 28 Oct 2014, 08:44 AM
Dear Mr. Martin,

When i click on the gridview multicolumn combo box (I'm using Gridview 2013) its take more time to drop down...
is there any way to make it fast.

Thanks
Rajesh

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;

namespace PharmaSol.Net
{
    public partial class frmSales : Form
    {
        DataSet ds;
        dbutils db;
        DataView dv;
        public frmSales()
        {
            InitializeComponent();
            ds = new DataSet();
            db = new dbutils();
            dv = new DataView();

        }

         private void frmSales_Load(object sender, EventArgs e)
        {
                string sql = "";
     
            sql = "SELECT prod_code as [Code],prod_name as [Description] ,prod_qty as Qty,prod_batch as batch, prod_exp as Expiry FROM dbo.fa_stock WHERE prod_qty>0";
             GridViewMultiComboBoxColumn col = (GridViewMultiComboBoxColumn)radGridSales.Columns["col_name"];
            ds = db.getDataSet(sql, "t1", 4);
            dv = new DataView(ds.Tables[0]);
            col.DataSource = dv;
            col.DisplayMember = "Description";
            col.ValueMember = "Code";
            col.FieldName = "Code";
            col.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.radGridSales.CellBeginEdit += new GridViewCellCancelEventHandler(radGridSales_CellBeginEdit);
            

        }

       bool isColumnAdded;

        private void radGridSales_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
        {

            if (radGridSales.CurrentColumn is GridViewMultiComboBoxColumn)
            {
                if (!isColumnAdded)
                {
                    isColumnAdded = true;
                    RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)radGridSales.ActiveEditor;
                    editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
                    editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Code"));
                    editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Description"));
                    editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Qty"));
                    editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("batch"));
                    editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Expiry"));

                    editor.AutoSizeDropDownToBestFit = true;
                }
            }
        }

        private bool isChangeCheck = false;
        private void radGridSales_CellValueChanged(object sender, GridViewCellEventArgs e)
        {
            //if (isChangeCheck) return;
            //GridViewRowInfo row = e.Row;
            //row.Cells[0].Value = "1";
        }



    }
}

0
Ralitsa
Telerik team
answered on 30 Oct 2014, 03:45 PM
Hi Rajesh, 

Thank you for contacting us. 

I confirm that this is known issue with our GridViewMultiComboBoxColumn. We already have it logged in our Feedback Portal. Here is the link: FIX. RadMltiColumnComboBox performance issue when drop down is open.

The issue was introduced in Q1 2013 and was fixed in Q1 2014 (2014.1.226). One way to avoid it is to upgrade to the latest version. If you do not want to upgrade your version of UI for WinForms you can add following code snippet in handler of CellBeginEdit event: 
bool isColumnAdded;
 
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (this.radGridView1.CurrentColumn is GridViewMultiComboBoxColumn)
    {
        if (!isColumnAdded)
        {
            isColumnAdded = true;
            RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridView1.ActiveEditor;
            editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("OrderID"));
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Quantity"));
            editor.AutoSizeDropDownToBestFit = true;
            //add this code snippet:
            editor.EditorControl.LoadElementTree();
        }
    }
}

Hope this will help you. Let me know if you have any another questions

Regards,
Ralitsa
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajesh
Top achievements
Rank 1
answered on 30 Oct 2014, 04:16 PM
Thank You Ralista,

Grate result, I have more than 10,000 rows in my table, and it's loading time is around 10 second? Is there any other method to improve loading speed or shall i upgrade to latest version?

Thanks & regards,
Rajesh S
0
Ralitsa
Telerik team
answered on 04 Nov 2014, 10:54 AM
Hi Rajesh, 

Thank you for your reply. 

I made a few test for performance when open the dropdown popup of MultiComboBoxColumn. 
1. With version Q1 2013 (2013.1.220) - it takes around 16 - 17 miliseconds to open MultiComboBoxColumn when use the workaround.  
2. With version Q3 2013 (2013.3.1016) - it takes around 16 - 17 miliseconds to open MultiComboBoxColumn when use the workaround.  
3. With version Q3 2014 (2014.3.1021) - it takes around 9 - 10 miliseconds to open MultiComboBoxColumn.

I was not able to reproduce loading time around 10 seconds. I also attached my sample project. Could you test the performance on your side?

If you still experience performance issue you could open support thread send us sample project which reproduce it, so we can investigate it and help you with it. 

Should you have further questions, I would be glad to help.
 
Regards,
Ralitsa
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Razeen
Top achievements
Rank 1
Answers by
Razeen
Top achievements
Rank 1
Martin Vasilev
Telerik team
shinu rag
Top achievements
Rank 1
Tajes
Top achievements
Rank 1
Rajesh
Top achievements
Rank 1
Ralitsa
Telerik team
Share this question
or