Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Dynamically Sorting when bound to datatable
posted

I am trying to get an ultragrid bound to a datatable maintain the sort order when ithe datatable is updated.

I am using UltraGrid v7.3.20073.38.

For example, first, I'll tell the grid that I'm going to maintain the sort myself:

private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
  e.Layout.Override.HeaderClickAction = HeaderClickAction.ExternalSortSingle
}

Then I create a datatable and set up the sort and databinding:

dataTable.Columns.Add("State", Type.GetType("System.String"));
           
dataTable.Rows.Add(new object[] { "Illinois"});
dataTable.Rows.Add(new object[] { "Alabama" });
dataTable.Rows.Add(new object[] { "New York" });
dataTable.Rows.Add(new object[] { "California" });

dataTable.DefaultView.Sort = "State ASC";

this.dataGridView1.DataSource = dataTable.DefaultView;

However if I now try and Add a row:

dataTable.Rows.Add(new object[] { "Iowa" });

the grid doesn't resort. Instead it looks like:

"Alabama"
"California"
"Illinois"
"New York"
"Iowa"

The frustrating thing here is that if I examine the DataView on the DataTable, it IS sorted like this:
Alabama
California
Illinois
Iowa
New York

Also, if I perform the same test with the .NET DataGridView control, it does perform the sort for me.  The only way I have been able to get the Ultragrid to do this is by calling:

ultraGrid1.DisplayLayout.Bands[0].SortedColumns.RefreshSort(true);

after the row is added or the data is updated.  Is there an automatic way to do this that I'm missing?

Thanks.