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

[Solved] Changing Column Headertext during Export

1 Answer 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 10 Jul 2014, 03:06 PM
Hi all, literally as the title says, I need to change column header(s) during the grid export without changing it on the UI...

I've tried loads of stuff I've found by searching both here and google...

I would have thought something like this would work : -



        Private Sub FrameworkGrid_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles Me.ItemCommand

            If e.CommandName.StartsWith("Export") Then

                For Each item In Me.Items

                    If TypeOf item Is GridHeaderItem Then

                        For Each cell As TableCell In CType(item, GridHeaderItem).Cells
                            StripTags(cell.Text)
                        Next

                    End If

                Next


            End If

        End Sub


But there never is a GridHeaderItem when doing that... It's just all the normal DataGridItems in the grid instead...

Basically, we've appended a load of css styling into some of the column headers and obviously when exporting we want to remove that and put it back to just plain text... I've got a function to strip the HTML using RegEx no problem ('StripTags') but I can't even get it that far...

Any suggestions?

1 Answer, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 10 Jul 2014, 03:33 PM
Just incase anyone wants a solution to this, I sorted it this way : -



        Private Sub FrameworkGrid_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles Me.ItemCommand

            If e.CommandName.StartsWith("Export") Then

                For Each col As GridColumn In Me.MasterTableView.AutoGeneratedColumns

                    col.HeaderText = StripTags(col.HeaderText)

                Next

            End If

        End Sub


        Function StripTags(ByVal html As String) As String

            Return Regex.Replace(html, "<.*?>", "")

        End Function


Works perfect :-)
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Share this question
or