We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changing filter on one SfDataGrid changes the filter on another SfDataGrid on the same form

Thread ID:

Created:

Updated:

Platform:

Replies:

146831 Aug 22,2019 05:43 AM UTC Aug 26,2019 05:37 AM UTC WinForms 3
loading
Tags: SfDataGrid
Larry Byrd
Asked On August 22, 2019 05:57 AM UTC

I am new to using SyncFusion controls and do not understand why this happens.  If I have more than one SfDataGrid on the same form, then changing the filter on one grid also changes the filter on the other grid even though I have not created any code to link them.  I want the grids to use the same data source, but not affect each other's filter or sorting.  I am using VS2019 and SF 17.2.0.34.  To re-create the problem just create a new winform project and add an sfDataGrid to Form1.  Set AllowFiltering to True.  Copy and paste the grid so that there are now two grids named sfDataGrid1 and sfDataGrid2.  Then add the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sfDataGridProblem
{
    public partial class Form1 : Form
    {
        private DataTable dt = new DataTable();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Selected", typeof(bool));
            dt.Rows.Add(new object[] { 1, false });
            dt.Rows.Add(new object[] { 2, true });
            dt.Rows.Add(new object[] { 3, false });
            dt.Rows.Add(new object[] { 4, true });
            dt.Rows.Add(new object[] { 5, false });

            sfDataGrid1.DataSource = dt;
            sfDataGrid2.DataSource = dt;
        }
    }
}


Farjana Parveen Ayubb [Syncfusion]
Replied On August 23, 2019 09:33 AM UTC

Hi Larry, 
 
Thank you for using Syncfusion controls. 
 
SfDataGrid performs the data related operations such as filtering and sorting for DataTable DataSource with the DataTable's RowFilter and Sort properties. So, its obvious that if you perform any operation in datagrid, underlying DataTable will also be updated since we updated the RowFilter & Sort properties.  
 
Hence, if you bind the same DataTable to 2 different SfDataGrid, another datagrid will get update. This is the behavior of SfDataGrid with DataTable.  
 
Meanwhile, you can overcome this scenario by converting the DataTable to dynamic object collection.  
 
Please refer the below code example 
 
List<dynamic> dynamicDt = dt.ToDynamic(); 
sfDataGrid.DataSource = dynamicDt; 
sfDataGrid1.DataSource = dynamicDt; 
  
 
Please let us know if you need any further details on this. 
 
Regards, 
Farjana Parveen A 


Larry Byrd
Replied On August 23, 2019 09:56 PM UTC

Thank you for your response.

Farjana Parveen Ayubb [Syncfusion]
Replied On August 26, 2019 05:37 AM UTC

Hi Larry, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon