Chris Lynch
Top achievements
Rank 1
Chris Lynch
asked on 11 Sep 2010, 05:03 PM
Is there an easy way to populate a Datatable from a Filtered gridview?
6 Answers, 1 is accepted
0
Hi Chris Lynch,
Yes, this is possible. However, you should do it manually by iterating all rows. Here is a sample:
I hope it helps.
Greetings, Jack
the Telerik team
Yes, this is possible. However, you should do it manually by iterating all rows. Here is a sample:
DataTable table = new DataTable();foreach (GridViewDataColumn column in this.radGridView1.Columns){ table.Columns.Add(column.Name, column.DataType);}foreach (GridViewRowInfo row in this.radGridView1.Rows){ DataRow dataRow = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { dataRow[i] = row.Cells[i].Value; } table.Rows.Add(dataRow);}I hope it helps.
Greetings, Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Lynch
Top achievements
Rank 1
answered on 17 Sep 2010, 07:07 PM
thanks
0
george mcnitt
Top achievements
Rank 1
answered on 02 Dec 2010, 07:50 PM
this currently isnt working in the current version of the grid control. It returns all the rows not just the filtered ones.
is there any update on how to get only the filtered rows?
is there any update on how to get only the filtered rows?
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 02 Dec 2010, 08:51 PM
Hello George,
this was changed in the Q3 2010 Release. An extract from the Q3 release notes reads:
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.
this was changed in the Q3 2010 Release. An extract from the Q3 release notes reads:
and here is the link to the Q3 Release notes
Hope that helps
Richard
0
Accepted
Ryan
Top achievements
Rank 1
answered on 02 Dec 2010, 09:15 PM
Here's a quick example
Dim table As New DataTable()For Each column As GridViewDataColumn In Me.grdClientSummary.Columns table.Columns.Add(column.Name, column.DataType)NextFor Each oChildItem In grdClientSummary.TableElement.ViewInfo.ChildRows Dim dataRow As DataRow = table.NewRow() For x As Integer = 0 To table.Columns.Count - 1 DataRow(x) = oChildItem.Cells(x).Value Next table.Rows.Add(dataRow)Next0
Hi All,
Please keep in mind that ChildRows represents the hierarchical view of Rows and when you have a grouping operation applied, the root level will contains only Group rows.
If you want to get only the filtered and sorted rows in a flat view without groping, you must use the DataView property of GridViewTemplate in this case:
Julian Benkov
the Telerik team
You can use ChildRows for this scenario just like Ryan said:
DataTable table = new DataTable();foreach (GridViewDataColumn column in this.radGridView1.Columns){ table.Columns.Add(column.Name, column.DataType);}foreach (GridViewRowInfo row in this.radGridView1.ChildRows){ DataRow dataRow = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { dataRow[i] = row.Cells[i].Value; } table.Rows.Add(dataRow);}Please keep in mind that ChildRows represents the hierarchical view of Rows and when you have a grouping operation applied, the root level will contains only Group rows.
If you want to get only the filtered and sorted rows in a flat view without groping, you must use the DataView property of GridViewTemplate in this case:
DataTable table = new DataTable();foreach (GridViewDataColumn column in this.radGridView1.Columns){ table.Columns.Add(column.Name, column.DataType);} foreach (GridViewRowInfo row in this.radGridView1.MasterTemplate.DataView){ DataRow dataRow = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { dataRow[i] = row.Cells[i].Value; } table.Rows.Add(dataRow);}I hope this helps.
Julian Benkov
the Telerik team