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

Problem with Fully resetting and re-initializing a GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

150372 Jan 3,2020 10:13 PM UTC Jan 13,2020 05:58 AM UTC WinForms 3
loading
Tags: GridDataBoundGrid(Classic)
Vishal
Asked On January 3, 2020 10:13 PM UTC

Hi

I have a simple winform application with a GridDataBoundGrid control displaying data from Sql server from a stored procedure. This grid control needs to source data from multiple stored procedures. The result sets coming from these stored procs are very different sets of columns. Hence i need to re-initialize the databoundgrid everytime before populating the results using the standard datasouce/datatable binding. In fact, without resetting, it was giving me very unpredictable results when i was running different stored procedures. I searched your forums and found a mechanism to reset the grid. Here it is:

                    this.ResultsGrid.BeginUpdate();
                    this.ResultsGrid.Binder.SuspendBinding();
                    this.ResultsGrid.DataSource = null;
                    this.ResultsGrid.DataMember = "";
                    this.ResultsGrid.Binder.InternalColumns.Clear();
                    this.ResultsGrid.Binder.ResetHierarchyLevels();
                    this.ResultsGrid.DataSource = new DataTable();
                    this.ResultsGrid.Binder.InitializeColumns();
                    this.ResultsGrid.EndUpdate();
                    this.ResultsGrid.Binder.ResumeBinding();

This is working however there is something not right with this. I have manually added a column to the grid that has a button to every row and associated a button click event. (code is below). When i press this button after going through a few refresh cycles on the grid, the button behaves strangely. it generates multiple click events on a single click. For example, if i have gone through two resets, it generates two clicks. 3 click events for 3 resets and so on!

So i think the reset/re-initialize of the DataboundGrid is not happening very cleanly. Some events or internal datastructures are still lingering around. Please help me fugure out the cleanest and fastest way to fully programmatically re-initialize the grid 100% (as if it was loaded for the very first time) with nothing internal lingering around from the prior data load.

BTW, i tried using dispose on the grid object and creating a new grid object but that did not work.

Here is the code i have to add a button column to the grid:

                GridBoundColumnsCollection columnCollection = (GridBoundColumnsCollection)this.ResultsGrid.Binder.InternalColumns.Clone();
                this.ResultsGrid.PushButtonClick += new GridCellPushButtonClickEventHandler(ResultsGrid_CellButtonClick);


                //Add OptionQuotes Button
                GridBoundColumn NewColumn = new GridBoundColumn();
                NewColumn.HeaderText = "View";
                NewColumn.MappingName = "View";
                NewColumn.StyleInfo.CellType = "PushButton";
                NewColumn.StyleInfo.Description = "ViewDetail";

                columnCollection.Add(NewColumn);
                this.ResultsGrid.Binder.GridBoundColumns = columnCollection;
                GridButtonsAdded = true;

                private void ResultsGrid_CellButtonClick(object sender, GridCellPushButtonClickEventArgs e)
               {
                      int rownum = e.RowIndex, colnum = e.ColIndex;
                         ---- My logic ---
               }

Here is the code fragment for Data Binding from Stored Procedure:

                DataTable dt = new DataTable();
                adapter = new SqlDataAdapter(cmd);
                adapter.Fill(dt);
                adapter.Dispose();
                cmd.Dispose();
                ResultsGrid.DataSource = dt;
                this.ResultsGrid.BeginUpdate();

Thanks!
Vishal

Arulpriya Ramalingam [Syncfusion]
Replied On January 6, 2020 12:00 PM UTC

Hi Vishal, 
 
Thank you for using Syncfusion products. 
 
We have validated the reported use case at our end by creating a simple sample. However, the GridCellButtonClick event triggers only once even after the binding source is changed. We suspect that the use case might be occurred due to some other grid settings or binding customization for GridDataBoundGrid. So, we request you to refer the below sample and let us know the customization that causes the issue at your end. That will be helpful for us to assist you further to provide you a better solution at the earliest. 
 
 
Please get back to us with simple screenshot, if we misunderstood your requirement. 
 
Regards, 
Arulpriya 


Vishal
Replied On January 11, 2020 02:25 PM UTC

Hi Arulpriya
Thank you for verifying. I am not sure why this happening for me however i have created a workaround for now by creating a simple bool variable to prevent adding (stacking) multiple event callbacks and ensure only one callback is registered. That worked for me.
Thanks,
Vishal




Arulpriya Ramalingam [Syncfusion]
Replied On January 13, 2020 05:58 AM UTC

Hi Vishal, 
 
Thank you for the update. 
 
We are glad that the reported use case has been resolved at your end by invoking the event callbacks based on conditions. Please back to us, if you have any other queries. 
 
Regards, 
Arulpriya 


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