Home Forums WinForms controls Xceed Grid for WinForms How to return filtered grid rows only?

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

    I have a grid with data in it.

    I do a search/find operation using code almost identical to the sample application (that comes with the Grid control). Now a subset of rows are highlighted.

    Then I apply the filter code similar to the sample application. Now just the highlighted rows are showing in the grid.

    Trouble is when I call GetSortedDataRows(…) the entire grid is returned, but what I want is only the subset currently displayed.

    Does anyone know an easy way to do this?

    This has implications for downstream operations such as printing and graphing of grid data.

    Any help greatly appreciated.
    ta
    Rob.

    Imported from legacy forums. Posted by Rob (had 2599 views)

    User (Old forums)
    Member
    Post count: 23064

    Maybe you could use a function like this:<pre>ArrayList GetFilteredDataRows(GridControl grid) {
    ArrayList filteredRows = new ArrayList();
    foreach(Xceed.Grid.DataRow row in grid.GetSortedDataRows(true))
    if (row.Visible) filteredRows.Add(row);
    return filteredRows;
    }</pre>Or in .NET 2.0:<pre>IList<Xceed.Grid.DataRow> GetFilteredDataRows(GridControl grid) {
    List<Xceed.Grid.DataRow> filteredRows = new List<Xceed.Grid.DataRow>();
    foreach(Xceed.Grid.DataRow row in grid.GetSortedDataRows(true))
    if (row.Visible) filteredRows.Add(row);
    return filteredRows;
    }</pre>

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the info – much appreciated.

    Your code looks good and I would have thought that it would work.

    However after trying it I discovered that the .Visible property remains true even for
    those rows that are not displayed (at least in Grid controlo v2.1 it does), which seems
    strange to me and is surely a bug. How can the .Visble property be true if the row is not
    actually visible?

    I have discovered a workaround that relies on the .Key property. I noticed (while stepping
    through in Debug mode) that the .Key property will be true for the filtered group of rows
    displayed in the grid, while it will be false for the other group (the remaining rows that
    are not part of the filtered group).

    With that in mind I devised this: (Note: the index of the filtered group is not always at index=0 !!)

    int grp_index=0;
    for(int j=0; j<gridControl1.Groups.Count; j++)
    {
    if((bool)gridControl1.Groups[j].Key == true)
    {
    grp_index = j;
    break;
    }
    }

    //now use grp_index to get at the filtered group only…
    foreach(Xceed.Grid.DataRow dataRow in this.gridControl1.Groups[grp_index].GetSortedDataRows(true))
    {
    // do something with dataRow from the filtered group…
    }

    However this is not very satisfactory as its not ‘obvious’ and I don’t know if this is by design
    or merely a coincidence that it works this way.

    It would be nice if the .Visible property actually reflected the reality of whether a row
    was visible or not.

    thanks again,
    regards,
    Rob

    Imported from legacy forums. Posted by Rob (had 3612 views)

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