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
75
Upgraded from v8.2 to v19.1: UltraGrid InitializeRow fires no longer synchronously when setting DataSource
posted

We have recently updated an old Windows Forms project from Infragistics NetAdvantage 2008 (v8.2) to the latest Ultimate UI 2019 (v19.1). Despite the versions being 10 years apart the upgrade was smooth.

We do run into an issue, though: The firing behavior of the UltraGrid InitializeRow event when setting DataSource has changed.

In the old version, InitializeRow was fired synchronously for every row while setting DataSource. In the new version it is not fired directly by setting DataSource, but asynchronously while repainting the control.

This change in behavior causes issues in our application. Sometimes global variables are set/calculated in InitializeRow which are consumed directly after setting DataSource. Because InitializeRow now fires asynchronously, this code no longer works correctly.

Probably this is just plain bad coding style but we have _a lot_ of InitializeRow events in the application and analyzing & modifying all might take a lot of time. Before we dive into this adventure, my question is...

Is there perhaps a setting or a code trick in the new UltraGrid to force the old behavior where InitializeRow fires synchronously while setting DataSource? Thanks!


Example code (Windows Forms, C#, .NET 4.x):

private static DataTable GetDataTable()
{
    var dataTable = new DataTable();
    dataTable.Columns.Add("Number", typeof(int));
    dataTable.Columns.Add("Text", typeof(string));
    for (var i = 0; i < 5; i++)
    {
        dataTable.Rows.Add(i, $"Row {i}");
    }
    return dataTable;
}

private void Button_Click(object sender, EventArgs e)
{
    textBox.Clear();
    textBox.AppendText("Begin setting UltraGrid.DataSource\r\n");
    ultraGrid.DataSource = GetDataTable();
    textBox.AppendText("End setting UltraGrid.DataSource\r\n");
}

private void UltraGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
    textBox.AppendText("InitializeRow\r\n");
}

Left v8.2, right 19.1:

Full sample source code available on request (includes v8.2 and v19.1 project for Visual Studio 2017)

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi, 

    I am pretty sure the change you are experiencing here was intentional. InitializeRow was never truly a synchronous process - even though it may have seemed that way. Setting the DataSource is not really synchronous, either. DataBinding is an ongoing thing. 

    Having said that, I tried this out in a small sample using your code and I get the same results you get. 

    But both of Divya's suggestions seem to work and force the IniitlaizeRow to fire before code execution proceeds. 

                Debug.WriteLine("Begin setting UltraGrid.DataSource\r\n");
                this.ultraGrid1.DataSource = GetDataTable();
    
                // Either one of these will do it.
                this.ultraGrid1.Update();
                //this.ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.FireInitializeRow);
    
                Debug.WriteLine("End setting UltraGrid.DataSource\r\n");
    

    In my testing, Update seems to work better. This forces the grid to paint and so it will probably be closer to the original behavior. For some reason, calling Refresh on the rows seems to cause InitializeRow to fire twice. I'm not sure why, but I suspect the Refresh might implicitly force an Update. 

Children