Welcome to the Xceed Community | Help
Community Search  
More Search Options

Hiding / Formatting DataGridItemProperty detail rows, and exporting them to Excel

Sort Posts: Previous Next
  •  06-11-2009, 3:20 PM Post no. 21559

    Hiding / Formatting DataGridItemProperty detail rows, and exporting them to Excel

    In my DataGridControl, I have defined Column objects for the columns of the master rows and DataGridItemProperty objects (like below) for the columns of the detail rows (PropertyDetailDescription in DataGridCollectionViewSource.DetailDescriptions).

    <xcdg:DataGridItemProperty Name="MyProp" DataType="{x:Type sys:Decimal}" />

     

    I have AutoCreateDetailConfigurations set to True on my DataGridControl, so the objects that the detail rows bind to have extra properties I don't want to be displayed as columns.  However, I am unable to specify and hide these columns in a DataGridItemProperty object like I can with a Column object (like below).  How is this possible with DataGridItemProperty objects?

    <xcdg:Column FieldName="MyHiddenProp" Visible="False" />

     

    Also, I wish to apply some formatting to the values in the cells of the detail rows.  With Column objects I can use CellContentTemplate (like below), but DataGridItemProperty objects don't have this facility.  How can this be done with DataGridItemProperty objects?

    <xcdg:Column FieldName="MyFormattedProp" CellContentTemplate="{StaticResource integralCellContentTemplate}" />

     

    One more thing, how do I export the contents of the detail rows to Excel?  The ExportToExcel() function of DataGridControl only exports the master rows.


    Associate, .NET Development
    Morgan Stanley, UK
  •  07-30-2009, 12:56 PM Post no. 23060 in reply to 21559

    Adding CellContentTemplate (or similar) to DataGridItemProperty in DetailDescriptions / Excel export

    OK, I resolved the matter of hiding columns in the DetailDescription by simply adding the Browsable(false) attribute to the properties I don't wish to show.

    However, I still need to apply a CellContentTemplate to my DataGridItemProperty objects in my DetailDescription.  To clarify my question, I have the following DataGridControl defined with a PropertyDetailDescription. The MyProperty Column in the main grid uses a custom CellContentTemplate (in order to format the decimal value in the cell and right-align it). How do I assign the same custom CellContentTemplate to the MyDetailProperty column in the PropertyDetailDescription?

    <igDock:ContentPane>
      <igDock:ContentPane.Resources>
        <xcdg:DataGridCollectionViewSource x:Key="mySource"
                                           Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:MyClass}}, Path=MyData}">

          <xcdg:DataGridCollectionViewSource.DetailDescriptions>
            <xcdg:PropertyDetailDescription RelationName="MyDetailData">
              <xcdg:PropertyDetailDescription.ItemProperties>
                <xcdg:DataGridItemProperty Name="MyDetailProperty" DataType="{x:Type sys:Decimal}" />
              </xcdg:PropertyDetailDescription.ItemProperties>
            </xcdg:PropertyDetailDescription>
          </xcdg:DataGridCollectionViewSource.DetailDescriptions>
        </xcdg:DataGridCollectionViewSource>
      </igDock:ContentPane.Resources>

      <xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource mySource}}"
                            AutoCreateDetailConfigurations="True">
        <xcdg:DataGridControl.Columns>
          <xcdg:Column FieldName="MyProperty" CellContentTemplate="{StaticResource myCellContentTemplate}" />
        </xcdg:DataGridControl.Columns>
      </xcdg:DataGridControl>
    </igDock:ContentPane>

    Also, I still need to know how to export the contents of the detail rows to Excel.  The ExportToExcel() function of DataGridControl only exports the master rows.

    Thanks,
    Jason


    Associate, .NET Development
    Morgan Stanley, UK
  •  07-30-2009, 3:05 PM Post no. 23068 in reply to 23060

    Re: Adding CellContentTemplate (or similar) to DataGridItemProperty in DetailDescriptions / Excel export

    The DataTemplate must be provided to the DataGridItemProperty's corresponding column's CellContentTemplate property.

    As for the ExportToExcel method not exporting detail rows, this is normal behavior. What you will need to do is create an instance of the ExcelExporter class and set its  DetailDepth property to the desired value, as demonstrated in the "Exporting" topic in the documentation.

    private void ExportButton_Click( object sender, RoutedEventArgs e )
    {
        ExcelExporter exporter =
     new ExcelExporter( this.OrdersGrid );
        
    // All details
        
    exporter.DetailDepth = int.MaxValue;
        
    // The grid (0) and groups (1)
        
    exporter.StatFunctionDepth = 1;     
        exporter.ShowStatsInDetails = false;
        exporter.ExportStatFunctionsAsFormulas = false;
        exporter.Export(
     "d:\\orders.xls" );

    } 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  08-13-2009, 9:20 AM Post no. 23323 in reply to 23068

    Re: Adding CellContentTemplate (or similar) to DataGridItemProperty in DetailDescriptions / Excel export

    Thank you for your help with this.  I have created a simple example project with the solution you suggested for applying a CellContentTemplate to detail columns.  However, there seems to be a lot of duplication.  I have to define my columns twice - once in DataGridControl.DetailConfigurations as Column elements (in order to set CellContentTemplate) and once in DataGridCollectionViewSource.DetailDescriptions as DataGridItemProperty elements (in order to set DataType and CalculateDistinctValues and suchlike).  Is this how it's supposed to be or is there a simpler/better way?

     

    Regarding the ExcelExporter solution, this works brilliantly, but I am still having a further issue with this... 

    I have some cases where I only want to export the expanded details.  The reason for this is because the property representing the detail of any particular master row results in a process that takes a long time and the user exporting the grid to Excel will only be interested in the rows they have already expanded.

    Is there any way to limit the export to just the master rows and the expanded detail rows?

     

    Thanks for all your help.

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
  •  08-21-2009, 1:53 PM Post no. 23467 in reply to 23323

    Re: Adding CellContentTemplate (or similar) to DataGridItemProperty in DetailDescriptions / Excel export

    Still looking for some support on this if possible at all?

    Thanks,

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
  •  08-21-2009, 1:58 PM Post no. 23469 in reply to 23323

    Re: Adding CellContentTemplate (or similar) to DataGridItemProperty in DetailDescriptions / Excel export

    This is the normal and expected way of defining things. The DataGridCollectionView/DataGridItemProperty represent data-related settings. Defining the columns and such represents UI-related settings.

    As for only exporting expanded details, this is currently not possible. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  11-22-2011, 2:14 PM Post no. 31360 in reply to 23060

    Re: Adding CellContentTemplate (or similar) to DataGridItemProperty in DetailDescriptions / Excel export

    Thanks for this snippet in your post "OK, I resolved the matter of hiding columns in the DetailDescription by simply adding the Browsable(false) attribute to the properties I don't wish to show.". I've been searching for this for a while ... and no documentation exists!  

    Thanks again,

    Alain 

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.