Answered by:
How to get all rows in datagrid when RowVirtualization is set to true?

Question
-
My datagrid has RowVirtualization enabled for better peformence. But when I need the items list in the datagrid I get all in the middle and end as empty. Only the rows that are loaded into datagrid are not empty. I have tried setting the RowVirtualization to false while I get the items list but that did not help. Please advice...
- Edited by GaiusBaltar Tuesday, November 22, 2011 7:33 AM
Tuesday, November 22, 2011 7:32 AM
Answers
-
I would write a method that takes an observablecollection and a collection of columns and returns a datatable.
Use reflection on the first row of the collection to work out the type.
- Marked as answer by Sheldon _Xiao Tuesday, November 29, 2011 8:56 AM
Tuesday, November 22, 2011 2:41 PM -
Hi GaiusBaltar,
If you enable the RowVirtualization, you could not get all rows from your DataGrid, however, you could get all row from your DataSource, or view(DataGrid.ItemSource).
best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Sheldon _Xiao Tuesday, November 29, 2011 8:56 AM
Thursday, November 24, 2011 5:41 AM
All replies
-
Your datagrid is presumably bound to a collection.
I would recommend working with that collection rather than rows in the datagrid.
Tuesday, November 22, 2011 7:49 AM -
Yes, my datagrid is bound to a collection but I have a function GetDataTableFromDataGrid(DataGrid myDatagrid) that returns datatable from datagrid. It works but I only get the full DataTable if row virtualization is false.Tuesday, November 22, 2011 8:00 AM
-
Why would you get a datatable from the grid when you could get it from the underlying collection?
Or... just use a datatable for everything and obviate the collection.
Tuesday, November 22, 2011 10:04 AM -
Because in the DataGrid user can edit, hide&show columns, re-arange columns and so on. My function returns DataTable from datagrid exacly as the columns are arranged and shown.Tuesday, November 22, 2011 10:12 AM
-
You can use the columns collection of the datagrid to capture what the user has done.Tuesday, November 22, 2011 10:33 AM
-
Then for each usercontrol that has DataGrid I have to make a function that returns DataTable from datagrid using columns collection and item collection (itemsssource). Thats a lot of work. I allready have one unique function that return DataTable from any DataGrid. Only row viritualization messes everything upTuesday, November 22, 2011 11:59 AM
-
I would write a method that takes an observablecollection and a collection of columns and returns a datatable.
Use reflection on the first row of the collection to work out the type.
- Marked as answer by Sheldon _Xiao Tuesday, November 29, 2011 8:56 AM
Tuesday, November 22, 2011 2:41 PM -
Hi GaiusBaltar,
If you enable the RowVirtualization, you could not get all rows from your DataGrid, however, you could get all row from your DataSource, or view(DataGrid.ItemSource).
best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Sheldon _Xiao Tuesday, November 29, 2011 8:56 AM
Thursday, November 24, 2011 5:41 AM -
Hi GaiusBaltar,
I am marking your issue as "Answered", if you have new findings about your issue, please let me know.
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, November 29, 2011 8:56 AM