This is a migrated thread and some comments may be shown as answers.

Export Custom Headers

5 Answers 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 22 Aug 2011, 06:12 PM
Hello,

I have had to use custom headers for a few columns in order to implement wrapping:

<telerik:GridViewDataColumn DataMemberBinding="{Binding QualityOpportunities}" Width="125" TextWrapping="Wrap" >
    <telerik:GridViewDataColumn.Header>
        <Grid>
            <TextBlock Text="Number of Quality Opportunities" TextWrapping="Wrap" HorizontalAlignment="center"/>
        </Grid>
    </telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>

However when I export the grid the column header turns into "System.Windows.Controls.Grid" instead of using the text of the text block. How can I get the column header to export correctly?

Thank you!

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 23 Aug 2011, 09:38 AM
Hi Jfkrueger,

 You may take a look at this forum thread on the same topic. There is a sample application, which you may download and review.

Please let me know in case you have any further questions.

Regards,
Didie
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
jfkrueger
Top achievements
Rank 1
answered on 23 Aug 2011, 03:34 PM
Thank you!

I'm not sure if this is how that other thread handles it but this is what worked for me (please let me know if this is a horrible hack or if I am doing it correctly):

    
Private Sub RadGridViewEvidenceBasedMedicine_ElementExporting(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridViewElementExportingEventArgs) Handles RadGridViewEvidenceBasedMedicine.ElementExporting
  
    If e.Context Is Nothing OrElse
        e.Context.ToString.Trim <> "Telerik.Windows.Controls.GridViewDataColumn" OrElse
        e.Value Is Nothing
  
        Return 
            
    End If
  
    If  e.Context.datamemberbinding.path.path = "QualityOpportunities" and e.Value.ToString.Trim = "System.Windows.Controls.Grid"
  
        e.Value = "Number Of Quality Opportunities"
  
    ElseIf e.Context.datamemberbinding.path.path = "QualityOpportunitiesWithCompliance" and e.Value.ToString.Trim = "System.Windows.Controls.Grid" 
  
        e.Value = "With Compliance"
  
    ElseIf e.Context.datamemberbinding.path.path = "ComplianceRate" and e.Value.ToString.Trim = "System.Windows.Controls.Grid"
  
        e.Value = "Compliance Rate"          
            
    End If
  
End Sub
0
Accepted
Dimitrina
Telerik team
answered on 24 Aug 2011, 07:48 AM
Hello Jfkrueger,

 This is fine, the only problem is that the value is hard-coded.

In the forum the export is done almost the same way except for the value used. There it is explained that you need just to set the Text of the e.Value in the ElementExporting event like so:

            if (e.Value != null && e.Value.GetType() == typeof(TextBlock))
                e.Value = (e.Value as TextBlock).Text;

It is up to you what you prefer.

Best wishes,
Didie
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
jfkrueger
Top achievements
Rank 1
answered on 24 Aug 2011, 06:59 PM

Your suggestion is definitely more efficient and I would prefer to use that however it does not work...

For vb.net I believe the conversion would be:

If e.Value IsNot Nothing AndAlso e.Value.GetType() Is GetType(TextBlock) Then
    e.Value = TryCast(e.Value, TextBlock).Text
End If

The problem is that for the columns where the type is displayed as the header instead of the header text  in the text block the Type is being returned as {System.Windows.Controls.Grid} and not TextBlock.

Once again, here is the column in question:

<telerik:GridViewDataColumn DataMemberBinding="{Binding QualityOpportunities}" Width="125" TextWrapping="Wrap" >
    <telerik:GridViewDataColumn.Header>
        <Grid
            <TextBlock Text="Number of Quality Opportunities" TextWrapping="Wrap" HorizontalAlignment="center"/>
        </Grid>
    </telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>

The header text that gets displayed is: "System.Windows.Controls.Grid".

Thanks again!        
0
jfkrueger
Top achievements
Rank 1
answered on 24 Aug 2011, 07:02 PM
Just had to remove the <grid> tags from within my header tags:

<telerik:GridViewDataColumn DataMemberBinding="{Binding QualityOpportunities}" Width="125" TextWrapping="Wrap"
    <telerik:GridViewDataColumn.Header
            <TextBlock Text="Number of Quality Opportunities" TextWrapping="Wrap" HorizontalAlignment="center"/>     </telerik:GridViewDataColumn.Header
</telerik:GridViewDataColumn>

Not sure why I had them there in the first place, must have copied from another example. Now it works perfectly with your code. Thank you!

Tags
GridView
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
jfkrueger
Top achievements
Rank 1
Share this question
or