Home Forums WinForms controls Xceed Grid for WinForms How can this be optimized?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15469 |

    This is the function that gets envoked when a value is selected in one of the filter cells. With a large number of rows this takes a very long time. But interestingly, when I filter again (when most of the rows are invisible), this function is lightning fast (with the same number of rows), which makes me think it has to do with redraw, or hiding of rows, or something.

    I call BeginInit and EndInit on the grid before calling this function – no difference.

    Any ideas? Thanks!

    public void ApplyFilters()
    {
    GroupBase parentGroup = this.ParentGroup;

    if (parentGroup == null)
    return;

    ReadOnlyDataRowList siblingDataRows = parentGroup.GetSortedDataRows(true);
    int siblingDataRowsCount = siblingDataRows.Count;

    int cellsCount = this.Cells.Count;

    for (int i = 0; i < siblingDataRowsCount; i++)
    {
    DataRow dataRow = siblingDataRows[i];

    bool rowMatchesFilter = true;

    for (int j = 0; j < cellsCount; j++)
    {
    FilterCell filterCell = (FilterCell)this.Cells[j];

    FilterInfo filterInfo;

    // If the filterCell is being edited, retrieve the editor’s currently selected filterInfo.
    if (filterCell.IsBeingEdited)
    filterInfo = filterCell.GetEditorFilterInfo();
    else
    filterInfo = filterCell.FilterInfo;

    // Evaluate wether or not the dataCell’s value matches the filter.
    FilterKeyType filterKeyType = filterInfo.Key.FilterKeyType;

    if (filterKeyType == FilterKeyType.AnyValue)
    continue;

    object cellValue = dataRow.Cells[j].Value;

    if (filterKeyType == FilterKeyType.NullValue)
    {
    if ((cellValue != null) && (cellValue != DBNull.Value))
    {
    // As soon as one of the dataRow’s cells does not match the filter, break the cell loop.
    rowMatchesFilter = false;
    break;
    }
    }
    else if (!(cellValue.Equals(filterInfo.Value)))
    {
    // As soon as one of the dataRow’s cells does not match the filter, break the cell loop.
    rowMatchesFilter = false;
    break;
    }
    }

    dataRow.Visible = rowMatchesFilter;
    }

    }

    Imported from legacy forums. Posted by Natalie (had 2848 views)

    User (Old forums)
    Member
    Post count: 23064

    I just ran a profiler on this and here’s the results:

    dataRow.Visible = rowMatchesFilter; took 127 seconds to execute 36000 which was flagged as one of the most expensive lines in the program.

    My question is, why is grid doing it? Can’t grid hide/show the rows behind the scenes and then just redraw once?

    Imported from legacy forums. Posted by Natalie (had 353 views)

    User (Old forums)
    Member
    Post count: 23064

    The grid does exactly that, it redraws only once… Note that setting the visibility of a grid element requires more processing than setting its BackColor, for example.

    To improve the filtering performance, an access to the internal code of the grid is required, so as to optimize it, with a caching system, hashing of row values, and so on…

    Imported from legacy forums. Posted by André (had 268 views)

    User (Old forums)
    Member
    Post count: 23064

    I have heavily customized the GridControl for our company software platform and added filtering capabilities. Instead of setting rows visible/invisible, I’ve applied the technique of making a custom grouping with 2 groups: 1 collapsed (for the hidden rows) and 1 expanded. This technique is also explained in the documentation, I think. It’s a lot faster than manually setting the rows visible/invisible.

    Imported from legacy forums. Posted by Tommy (had 3989 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.