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. Image for the cookie policy date

GDBD Refresh problem with same DataTable but data changed

I defined a GridDataBoundGrid and a DataTable in my code. I have a methos called ShowTable which has following lines: this.grid.DataMember = ""; this.grid.DataSource = dataTable; The first time there''s no problem of display. But when the data in my dataTable changed, I need to refresh the grid so ShowTable will be called again. Somehow the grid didn''t bind to the dataTable. So the display just show the header of the table, no data. How to solve this? Thanks, Mechelle

6 Replies

AD Administrator Syncfusion Team March 30, 2005 12:46 PM

Try this to see if if avoids this problem. this.grid.DataMember = ""; this.grid.DataSource = null; this.grid.DataSource = dataTable; //maybe add one or both of of these lines this.grid.Binder.InitializeColumns(); this.grid.Refresh();


ME Mechelle March 30, 2005 01:19 PM

Thanks for the reply. I tried the recommeded code, but it doesn''t work either. Mechelle


AD Administrator Syncfusion Team March 30, 2005 01:56 PM

>>when the data in my dataTable changed What do you mean by this? Do you mean the datatable is destroyed and reloaded as a new DataTable with different columns? Or, do you mean that just some other process has modifed values in the DataTable? If you are destoying the DataTable while it is still set as the grid''s datasource, then this would be a problem. You should first set grid.DataSource = null; then destroy the DataTable and recreate it, and then reset it as teh grid''s DataSource. If you will explain more about what you are doing, then maybe we can suggest some solution.


ME Mechelle March 30, 2005 03:22 PM

In the method of ShowTable(), my datatable is defined as following: dataTable.Reset(); dataTable.AcceptChanges(); dataTable.Columns.Add("Computers", typeof(String)); dataTable.Columns.Add("Result",typeof(String)); BuildTableContents(); //Updates latest data from a SortedList to this dataTable grid.DataMember = ""; grid.DataSource = null; grid.DataSource = dataTable; When I say dataTable changes, I mean the data(contents) changed. The schema doesn''t. And I can verify that the data in the dataTable has been updated through the debugger. But "grid.DataSource = dataTable;" doesn''t bind the grid to the table data for the 2nd time. Although the first time it binds no problem. Somehow the 2nd time the column name is showed up, but no data. Mechelle


AD Administrator Syncfusion Team March 30, 2005 04:43 PM

If the schema does not change, try calling DataTable.Clear instead of DataTable.Reset. The reset causes a similar problem if you try doing something like this with a Windows Forms DataGrid. Here is a little sample that has a button that loads a Datatable many times with different data using DataTable.Clear. http://www.syncfusion.com/Support/user/uploads/GDBG_ResetDatasource_75ea892e.zip


ME Mechelle March 30, 2005 05:02 PM

Thank you for the suggestion. Using DataTable.Clear() fix the problem. Thank you again. Mechelle

Loader.
Live Chat Icon For mobile
Up arrow icon