This is a migrated thread and some comments may be shown as answers.

Help filtering rows

5 Answers 320 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Filleau
Top achievements
Rank 1
Filleau asked on 12 Nov 2010, 05:21 PM
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

5 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 05:31 PM
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
0
Filleau
Top achievements
Rank 1
answered on 12 Nov 2010, 05:43 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 05:48 PM
Glad that helped. Anything else, just let me know

Richard
0
superold
Top achievements
Rank 1
answered on 25 Jul 2013, 06:18 PM
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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Jul 2013, 03:36 PM
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 >>
Tags
GridView
Asked by
Filleau
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Filleau
Top achievements
Rank 1
superold
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or