Export WPF ListView data to excel
WPF
3
Posts
3
Posters
0
Views
1
Watching
-
Hi, I am using a WPF ListView bound to an observable collection to display records in the form of a Grid. How can I export this data in ListView to excel?
Pankaj Chamria, Software Programmer.
-
Hi, I am using a WPF ListView bound to an observable collection to display records in the form of a Grid. How can I export this data in ListView to excel?
Pankaj Chamria, Software Programmer.
-
The ListView in WPF is so different to the Forms one. :~ Maybe the problem is how to iterate inside the ListView items. Here it is:
GridView grid = source.View as GridView; if (grid == null) { //Sorry, only for GridView views return; } foreach (GridViewColumn col in grid.Columns) { //value of header is col.Header } foreach (Object item in source.Items) { PropertyInfo\[\] dataFields = item.GetType().GetProperties(); int i = 0; foreach (GridViewColumn col in grid.Columns) { try { //Get the name of field displayed on grid string strPath = ((Binding)col.DisplayMemberBinding).Path.Path; //Get the field value object propValue = GetValue(item, source.Items, strPath); //Value of cell is propValue } catch (Exception) { } } }
I think it will be easier to export (to excel, pdf or anything) from here.