I am getting the below cross thread operation coming from the synfusion dll while I am applying filters.

The issue comes randomly. While I apply filters. In my inside code I haven't added any code for filters as it is automatically working using syncfusion.  Require your urgent help in this. The application is used for adding a powerpoint pluging


using Syncfusion.WinForms.DataGrid;

using Syncfusion.WinForms.DataGrid.Enums;

using Syncfusion.WinForms.DataGrid.Events;

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

using System;

using System.Collections.Generic;

using System.Data;

using System.Diagnostics;

using System.Linq;

using System.Threading;

using System.Windows.Forms;

using DataRow = System.Data.DataRow;


namespace Abcfile

{

    public partial class SelectData : Form

    {

        private DataTable credentialsDataTable;


        public SelectData(DataTable dt)

        {


            InitializeComponent();

            credentialsDataGrid.BeginInit();

            credentialsDataTable = dt;


            DataColumn selectionColumn = credentialsDataTable.Columns.Add("Selection", typeof(bool));

            DataColumn rowSortColumn = credentialsDataTable.Columns.Add("RowSort", typeof(int));


            // Set up the columns with default values.

            foreach(System.Data.DataRow r in credentialsDataTable.Rows)

            {

                //r.BeginEdit();

                r["Selection"] = false;

                r["RowSort"] = 0;

                //r.EndEdit();

            }


            selectionColumn.SetOrdinal(0);

            rowSortColumn.SetOrdinal(1);


            credentialsDataGrid.DataSource = credentialsDataTable;

            credentialsDataGrid.EndInit();

            credentialsDataGrid.Columns["Selection"].HeaderText = "✓";

            credentialsDataGrid.Columns["Selection"].AutoSizeColumnsMode = AutoSizeColumnsMode.ColumnHeader;


            credentialsDataGrid.Columns["RowSort"].HeaderText = "#";

            credentialsDataGrid.Columns["RowSort"].AutoSizeColumnsMode = AutoSizeColumnsMode.ColumnHeader;


            // Skipping the first column, which is the index.

            foreach (GridColumn c in credentialsDataGrid.Columns.Skip(2))

            {

                c.AllowEditing = false;

            }


        }


        private void SelectData_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e)

        {

            if (e.Column.MappingName == "Selection")

            {

                DataRow row = ((System.Data.DataRowView) e.Record).Row;

                //row.BeginEdit();

                row["RowSort"] = e.NewValue == CheckState.Checked ? Convert.ToInt32(credentialsDataTable.Compute("max([RowSort])", string.Empty)) + 1 : 0;

               // row.EndEdit();


                btn_Generate.Enabled = GetSelectedRows().Count() > 0 | e.NewValue == CheckState.Checked;

                btn_Clear.Enabled = GetSelectedRows().Count() > 0 | e.NewValue == CheckState.Checked;


            }

        }


        public DataRow[] GetSelectedRows()

        {

            return credentialsDataTable.Select("Selection").OrderBy(row => row["RowSort"]).ToArray();

        }


        private void SelectData_FormClosing(object sender, FormClosingEventArgs e)

        {

            e.Cancel = true; // Cancels the close event.

            Hide();

        }


        private void btnExit_Click(object sender, EventArgs e)

        {

            Hide();

        }


        private void btn_Clear_Click(object sender, EventArgs e)

        {

            btn_Generate.Enabled = false;

            btn_Clear.Enabled = false;

            foreach (DataRow r in credentialsDataTable.Select("Selection"))

            {

                r["Selection"] = false;

                r["RowSort"] = 0;

            }

        }

        private void btn_SelectAll_Click(object sender, EventArgs e)

        {

            credentialsDataTable.BeginInit();

            btn_Generate.Enabled = true;

            btn_Clear.Enabled = true;

            int i = 0;


            foreach (DataRow r in credentialsDataTable.Rows)

            {

                r["Selection"] = true;

                r["RowSort"] = ++i;

            }

            credentialsDataTable.EndInit();

        }



        private void btn_Generate_Click(object sender, EventArgs e)

        {

            Thread generateThread = new Thread(() => {

                PowerPoint.Application powerpoint = Globals.Addin.Application;

                if (!powerpoint.hasSlides())

                {

                    ToolbarMsgBoxes.showErrorMessage("PowerPoint does not contain any slides.");

                    return;

                }


                DefaultTemplate.generatePage(powerpoint, GetSelectedRows());

            });


            generateThread.Start();


        }


        private void btn_ClearFilters_Click(object sender, EventArgs e)

        {

            try

            {

                credentialsDataGrid.ClearFilters();

            }

            catch (Exception ex)

            {

                ToolbarMsgBoxes.showErrorMessage(ex.Message);

            }


        }

    }

}





5 Replies

SD Swathi Dhatchanamoorthi Syncfusion Team May 22, 2023 03:53 PM UTC

Anmol,

We are currently checking your reported problem with provided information and we need a time to validate this. We will update you with further details on May 24, 2023.




AG Anmol Gupta May 23, 2023 06:28 AM UTC

Sure thanks. 

Please find the screenshot of properties of syncfusion Grid. Hope it helps.



AG Anmol Gupta May 23, 2023 06:32 AM UTC

Screenshot:





AG Anmol Gupta May 23, 2023 06:34 AM UTC

Screenshot2



SJ Sathiyathanam Jeyakumar Syncfusion Team May 24, 2023 04:53 PM UTC

Anmol,

We attempted to replicate the reported issue using the provided information. We prepared the sample with a DataTable as the ItemsSource and set all settings as per the screenshots. However, we were unable to replicate the reported issue from our end. Could you please provide us with the following details to help us replicate the reported problem?

  • How did you apply the filter to the DataGrid? Was it applied through UI or Programmatic Filtering?

  • Would it be possible to share a video illustration of the issue or provide the exact replication procedure?

  • Is it possible to provide an issue reproducible sample or replicate the issue in the attached sample?


Attachment: Sample_b4d54518.zip

Loader.
Up arrow icon