Hi all,

I need help with this code:

DataAdapter1.Fill(DataSet1);
DataSet1.Tables[0].DefaultView.Sort = "sortcolumn";
BindingSource1.DataSource =  DataSet1.Tables[0].DefaultView;

After execution, the "DataSet1.Tables[0].DefaultView.Sort" property is reset to empty string.
What might be the cause of this, and how can this be avoided?

Thanks

A BindingSource also has a "Sort" property.

I have not investigated the actual logic for this, but if the bindingsource.sort property is set to an empty string, the behaviour your are seeing will occur.

If you set bindingsource.Sort to null before assigning the "DataSource", it will not clear the DefaultView.Sort value.

Exactly!

The problem was that in the designer window, when I previously set the Sort property of the BindingSource to some value, and then later I deleted it, the designer was initializing it's value to an empty string, not to null, which was causing the problem.
I just deleted the initialization for the Sort property from the designer code (I suppose you can't set the value to null from the designer window).

Thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.