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
802
Speed Up UltraGrid Performance
posted

Hello,

 

I had a question concerning WinGrid performance when it comes to looping through the entire grid to obtain the rows which have been modified. Right now I created an unbound column called ‘Edited’, which is simply a Boolean column that is currently used to indicate whether or not changes have occurred in a row.

 

Here is the code I have written so far to accomplish looping through the grid to obtain the rows that contain changes.

 private ArrayList GetEditedRows()        {            ArrayList rows = new ArrayList();                        try            {                RowsCollection AllGridRows = this.ultraGrid1.Rows;                                if (this.ultraGrid1.Rows.IsGroupByRows)                {                    //Important to handle this before altering the BindingSource for the ultragrid.                     // Get a list of the expanded groups in the view.                     ArrayList expandedGroups = GetExpandedGroups();                    // Get a list of the sorted/grouped columns in the view.                    ArrayList SortedColumns =                         new ArrayList(this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns);                     this.ultraGrid1.DisplayLayout.Bands[0].ClearGroupByColumns();                    // Check each row in the ultragrid to see if any of them contain changes.                    foreach (UltraGridRow UGR in AllGridRows)                    {                        if (((bool)UGR.Cells["Edited"].Value).Equals(true))                        {                            rows.Add(UGR);                        }                    }                    // Reset the columns back into their groupby order.                    foreach (UltraGridColumn column in SortedColumns)                    {                        this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Add(column.Key, false, true);                    }                     // Expand the first row in the grid.                    if (expandedGroups != null || expandedGroups.Count > 0)                        SetExpandedGroups(expandedGroups);                 }                else                {                    foreach (UltraGridRow UGR in AllGridRows)                    {                        // If  the 'Edited' is checked in the current row, then                        // there are changes that exist.                                                if(((bool)UGR.Cells["Edited"].Value).Equals(true))                        {                            rows.Add(UGR);                        }                    }                }                return rows;            }            catch (Exception Error)            {                MessageBox.Show(Error.Source + ", " + Error.Message);                return null;            }  

This code works perfectly, however I do run into a problem when I have 5000+ rows in my grid. The grid pauses for maybe 30 seconds or more, which seems to be an excessive amount of time for this operation to be performed to me. Is there possibly a faster way I can speed up the processing or is there another type of RowsCollection I can get from the UltraGrid like for instance RowsEditCollection? Is there a solution or workaround in the Knowledge Base perhaps? I was not succesful in finding though. Please advise.

 

Adrian

 

  • 1725
    posted

    One of the things I've done in cases like this is to keep a Dictionary around and when the row (or row and cell if I care about that) is modified I add the row/cell to the dictionary if it is not already there..when the row is no longer dirty (however you figure that out) I remove it from the dictionary. That way I can track the rows that have been changed dynamically and don't have to loop over the grid rows.  There may be other simple structures (List<T> or something) that might work for you if a Dictionary is to much.

    Just a suggestion.

  • 469350
    Offline posted

    Have you read this?  WinGrid Performance Guide