Help filtering rows

6 posts, 1 answers
  1. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 12 Nov 2010 Link to this post

    Hi,

    I would like to filter my Radgridview and then iterate thru filtered rows. Can't be more simple... I use Winform Q3-2010

    I have no problem to apply the filter. The RadGridView display only filtered rows. It is OK
    But when I want to iterate in them, I read all the rows !!! 

    Here my code

    Dim serveursource As String = "SRV-13-1;SRV-59-2"
      Dim f As Integer
      Dim words As String() = serveursource.Split(New Char() {";"c})
      Dim strRowFilter As String
      Dim filter As New FilterDescriptor()
      filter.PropertyName = "Dest_Serveur"
      filter.[Operator] = FilterOperator.IsEqualTo
      filter.IsFilterEditor = True
      RadGridView1.EnableFiltering = True
      ' Use For Each loop over words and display them
      Dim word As String
      For Each word In words
          If word <> "" Then
              filter.Value = word
              Me.RadGridView1.FilterDescriptors.Add(filter)
              f = 0
              For Each rowInfo As GridViewRowInfo In RadGridView1.Rows
                  f += 1
              Next
              MsgBox(word & "Nb of rows:" & Me.RadGridView1.Rows.Count.ToString & ">>" & f.ToString)
          End If
      Next
    What is wrong ?

    Thanks
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Nov 2010 Link to this post

    hello,

    This is a new change in Q3. the release notes read:

    BREAKING CHANGE: The Rows collection of GridViewTemplate now contains all bound/unbound rows. The filtered, grouped, and sorted lists of rows can be accessed from the ChildRows collection of GridViewTemplate or from every GridViewRowInfo in a hierarchical view of rows.

    you can see all the release notes for this version here

    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 12 Nov 2010 Link to this post

    Thanks Richard.

    This is it ! It work now.

    This change (and certainly others) is boring me because I will have to modify a lot of my sources...

    Regards
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Nov 2010 Link to this post

    Glad that helped. Anything else, just let me know

    Richard
  6. Jorge Delgado-Lopez
    Jorge Delgado-Lopez avatar
    82 posts
    Member since:
    Aug 2007

    Posted 25 Jul 2013 Link to this post

    Hi!
    I am updating an old winforms client which runs on telerik 2010.2.10.914.

    Where can I find the filtered rows? you see, I have bound objects and a couple of columns which are created dynamically, the cells are populated by traversing the .Rows property, but when a filter is applied the .Rows property only returns the visible rows and thus I can not update the cells with the new data.

    I know I could upgrade so I get the functionality you describe above, but it would take several days of work (I have done a lot of hacks to get RadControls to work correctly as of 2010) which I would have to find and work with, I checked the braking changes log from 2010 onwards and they are just too many.

    Also I could update the cells with events, CellFormatting? or CellValueNeeded? what about sorting and filtering, would they still work?

    - jorge
  7. Dess
    Admin
    Dess avatar
    1608 posts

    Posted 30 Jul 2013 Link to this post

    Hello Jorge,

    Thank you for contacting Telerik Support.

    As it was mentioned below by Richard, Q3-2010 release has a breaking change in the Rows collection of the RadGridView (RadGridView.Rows now contains all bound/unbound rows; The filtered, grouped and sorted rows can be accessed through RadGridView.MasterTemplate.ChildRows). The previous behaviour was that RadGridView.Rows and RadGridView.MasterTemplate.ChildRows both contained only the filtered, grouped, and sorted rows. The actual full data collection was held in the DataSource.
    In your case, as you manually add an additional column to your grid run time, you can not populate with data all column cells using RadGridView.Rows, if you have directly applied filter to the grid. The filtered rows remain empty for this column. It is appropriate to subscribe for the CellFormatting event and there to populate with data the manually added column cells. Thus when the filter is removed all new visual cells should be filled.
    My example contains a RadGridView (version 2010.2.10.914) which DataSource is the standard Employees table from NWind.mdb. I have also added a FilterDescriptor in order to reduce the initial rows number loaded in the grid:
    private RadGridView grid;
     
           public Form1()
     
           {
               InitializeComponent();
     
               this.grid = new RadGridView();           
               grid.Size = new System.Drawing.Size(1500, 600);         
               grid.EnableFiltering = true;              
               grid.AutoGenerateColumns = true;
               grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
               grid.DataSource = bindingSource1;
     
               GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn("TextColumn");
               grid.Columns.Add(textBoxColumn);
                
               FilterDescriptor filter = new FilterDescriptor();
               filter.PropertyName = "LastName";
               filter.Operator = FilterOperator.Contains;
               filter.Value = "d";
               filter.IsFilterEditor = true;
               grid.FilterDescriptors.Add(filter);
     
               grid.CellFormatting += grid_CellFormatting;
     
               this.Controls.Add(grid);
           }

    private void Form1_Load(object sender, EventArgs e)
           {
               this.employeesTableAdapter.Fill(this.nwindDataSet.Employees);
           }

    private void grid_CellFormatting(object sender, CellFormattingEventArgs e)
           {
               if (e.CellElement.ColumnInfo.Name == "TextColumn")
               {
                   int index = -1;
     
                   if (e.CellElement.RowInfo.DataBoundItem != null)
                   {
                       index = this.nwindDataSet.Employees.Rows.IndexOf(((DataRowView)e.CellElement.RowInfo.DataBoundItem).Row);
                   }
     
                   e.CellElement.Text = string.Format("text {0}", index + 1);
               }
           }

    The manually added TextColumn is filled for each row with the item index in the DataSource collection. Please, find the attached pictute for more details.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready