This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am wanting to print the groupings (DataGrid.GroupRowHeaderTemplate) when I print the DataGrid. Is there a way to get to the DataGridGroup items from the DataGrid? And in turn, the DataGridGroup.Children collection? Will they be in the same order as presented on the screen? Currently, I'm looping through the items using the DataGrid.Items.Count and the DataGrid.Columns.Count. Then, I am calling DataGrid.GetCell(rowIndex, columnIndex) and converting each cell to something I can print. This is working great and flowing across pages (vertically and horizontally) beautifully. I just need to handle the group row headers. If you have any suggestions on how to proceed, they would be appreciated. Thanks. |
|
|
I also have the need to export the group row headers when I export the DataGrid. Currently, I am using the DataGridExporter.Csv.WriteFile(DataGrid grid, string filename). Any ideas on how to export the group row header information as well? |
|
|
Hello Jared The best way to get the grouping information is to iterate through the DataGrid.DisplayedItemsSource. This will be filled with instances of DataGridGroup and the raw model objects. This collection will be in order as displayed by the DataGrid, i.e. the items are sorted (if sorting is applied) and the DataGridGroup objects precede the items that they group. I would recommend iterating this list not only to get the group objects, but also to get the cell values as well. Rather than using DataGrid.GetCell, you can create a new instance of DataGridCell by passing in the row content object and an instance of DataGridColumn into the DataGridCell constructor. (the row content objects are the raw model objects that you'll find in the DisplayedItemsSource, and you can get the DataGridColumn instances by iterating the DataGrid.EffectiveColumns collection). This will effectively be the same as using DataGrid.GetCell(int, int), and will have the same performance. For the csv exporting, I recommend writing your own exporter so you can export the group rows however you like. Create a new class that extends the DataGridExporter class. Then implement the WriteCore method. Here is the code for our csv exporter to get you started:
The first loop is for writing the columns headers at the top of the csv file. Next, rather than iterating through the DataGrid.ItemsSource, you should iterate DataGrid.DisplayedItemsSource. For each iteration, check if you have found a DataGridGroup or not. If you have found a group, then write it out however you want. If it is not a group, then use the code above to export it out in the usual way. Let me know if you have any questions. Jason Fauchelle |
|