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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

resetting the DataSource in a GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

49665 Sep 22,2006 04:03 PM UTC Nov 28,2006 06:53 AM UTC WinForms 6
loading
Tags: GridControl
Timothy Duly
Asked On September 22, 2006 04:03 PM UTC

I am currently trying to reset the datasource in a GridDataBoundGrid to a new datasource. I am doing this as I am changing the structure of the dataset that the datasource points to at runtime (extra columns and rows added).

I have tried the code below but it does not work as I get an exception at the last line of code (also pasted beneath).

//dataModel is an object of custom type Models
DataSet = new DataSet();
serializer = new XmlSerializer(typeof(Models));
mStream = new MemoryStream();
serializer.Serialize(mStream,dataModels);
mStream.Position = 0;
ds.ReadXml(mStream);

gridDataBoundGrid1.DataMember = "";
gridDataBoundGrid1.DataSource = null;
gridDataBoundGrid1.Binder.ResetHierarchyLevels();
gridDataBoundGrid1.DataSource = ds;
gridDataBoundGrid1.DataMember = ds.Tables["Model"].TableName;

---------------------------------------------
Exception Received:
An unhandled exception of type ''System.FormatException'' occurred in mscorlib.dll

Additional information: Input string was not in a correct format.
---------------------------------------------

I hope that someone can help as I''m getting quite frustrated.

Administrator [Syncfusion]
Replied On September 25, 2006 06:30 AM UTC

Hi Tim,

Try this code to reset the datasource in a grid.

gridDataBoundGrid1.BeginUpdate();
gridDataBoundGrid1.Binder.SuspendBinding();

gridDataBoundGrid1.DataMember = "";
gridDataBoundGrid1.DataSource = null;

//Clear the Column and it''s type.
gridDataBoundGrid1.Binder.InternalColumns.Clear();

gridDataBoundGrid1.Binder.ResetHierarchyLevels();
gridDataBoundGrid1.DataSource = ds;
gridDataBoundGrid1.DataMember = ds.Tables["Model"].TableName;

gridDataBoundGrid1.EndUpdate();
gridDataBoundGrid1.Binder.ResumeBinding();

Let me know if this helps,

Best Regards,
Haneef

Timothy Duly
Replied On September 25, 2006 07:37 AM UTC

Hi,

I tried the code that you posted and I still get the same error when trying to set the datamember.

If I switch the assignment ordering of DateMember and DataSource around, the exception is thrown on the last executable statement so it is not an error that is exclusive to the DataMember assignment itself.

I am using Syncfusion v3.3.0.0 if that helps.

Regards,

Tim


>Hi Tim,

Try this code to reset the datasource in a grid.

gridDataBoundGrid1.BeginUpdate();
gridDataBoundGrid1.Binder.SuspendBinding();

gridDataBoundGrid1.DataMember = "";
gridDataBoundGrid1.DataSource = null;

//Clear the Column and it''s type.
gridDataBoundGrid1.Binder.InternalColumns.Clear();

gridDataBoundGrid1.Binder.ResetHierarchyLevels();
gridDataBoundGrid1.DataSource = ds;
gridDataBoundGrid1.DataMember = ds.Tables["Model"].TableName;

gridDataBoundGrid1.EndUpdate();
gridDataBoundGrid1.Binder.ResumeBinding();

Let me know if this helps,

Best Regards,
Haneef

Timothy Duly
Replied On September 25, 2006 08:41 AM UTC

I originally had ShowTreeLines set to True and after reading around noticed that this had caused a problem for others also. If I set ShowTreeLines to ''false'' then I no longer get the FormatException error but code that I ran for showing/expanding and collapsing columns no longer referenced the correct columns and the column displays were all out of kilter.

So currently the only way to get the grid to behave properly is still to destroy the old grid and dataset and create new instances of them every time I change the dataset.

Administrator [Syncfusion]
Replied On September 25, 2006 10:50 AM UTC

Hi Tim,

Can you try the code below, to see if this helps in resetting the datasource for the grid.

this.gridDataBoundGrid1.BeginUpdate();
this.gridDataBoundGrid1.DataSource = null;
this.gridDataBoundGrid1.DataMember = "";
this.gridDataBoundGrid1.Binder.ResetHierarchyLevels();
this.gridDataBoundGrid1.DataSource = newDataSet.Tables[0];
this.gridDataBoundGrid1.Binder.InitializeColumns();
this.gridDataBoundGrid1.EndUpdate();

Thanks,
Rajagopal

Leema Rose
Replied On November 27, 2006 01:13 PM UTC

While setting ShowTreeLines property to true when changing the dataset.

Exception occurs - how to handle it.



Administrator [Syncfusion]
Replied On November 28, 2006 06:53 AM UTC

Hi Leema,

Thanks for the update.

One way around the problem is to turnoff the ShowTreeLines right after your grid.BeginUpdate call, and then turn it back on later right before your grid.EndUpdate.

this.gridDataBoundGrid1.Binder.SuspendBinding();
this.gridDataBoundGrid1.BeginUpdate();
gridDataBoundGrid1.ShowTreeLines = false;
....
this.gridDataBoundGrid1.Binder.ResumeBinding();
gridDataBoundGrid1.ShowTreeLines = true;
this.gridDataBoundGrid1.EndUpdate();

Best Regards,
Haneef

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.

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

;