ASP.NET/VB.NET - in VB.NET how do you change the Font for just a single column only in the GridView control?

sqdperu
sqdperu used Ask the Experts™
on
ASP.NET Web form app with VB.NET back end code.

Is there a way in the RowDataBound event in VB.NET to change the Font used for just a single column in the GridView control?

I have a GridView bound to a data source and for the a single column only in the GridView I want to use the Wingdings3 font so I can put the triangle symbol in that column.
Example of label/legend on form:
Wingdings3.PNG
Here is my code that I just started changing the first nested IF.  The line I added for the Font change is incorrect syntax.  What would the syntax be?
I don't need to do it at the cell level necessarily if there is a way to change the whole single column to that font too, that would work as long as the header for that column would not change or could be blank:

    Public Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridViewHierachical.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.Cells(1).Text = "Delayed" Then
                e.Row.Cells(1).ForeColor = Drawing.Color.Red
                e.Row.Cells(1).Text = "p"  ' <== Wingdings3 character used to produce a down pointing solid triangle
                ' Change the font for column one to wingdings3 ==>  GridViewHierachical.Columns(1).DefaultCellStyle.Font = New Drawing.Font(GridViewHierachical.DefaultCellStyle.Font)
            End If
            If e.Row.Cells(1).Text = "Potential Early" Then
                'e.Row.Cells(1).BackColor = Drawing.Color.Yellow
                e.Row.Cells(1).BackColor = Drawing.ColorTranslator.FromHtml("#FFD100")
                e.Row.Cells(1).ForeColor = Drawing.Color.Black
            End If
            If e.Row.Cells(1).Text = "Potential Delay" Then
                'e.Row.Cells(1).BackColor = Drawing.Color.Yellow
                e.Row.Cells(1).BackColor = Drawing.ColorTranslator.FromHtml("#FFD100")
                e.Row.Cells(1).ForeColor = Drawing.Color.Black
            End If
            If e.Row.Cells(1).Text = "No Delay" Then
                e.Row.Cells(1).BackColor = Drawing.Color.Green
                e.Row.Cells(1).ForeColor = Drawing.Color.Black
            End If
        End If

    End Sub

Open in new window


Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Never mind.  I figured out myself.   Code below -

VB.NET code:
    Public Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridViewHierachical.RowDataBound

         If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.Cells(1).Text = "Delayed" Then
                e.Row.Cells(1).ForeColor = Drawing.Color.Red
                e.Row.Cells(1).Text = "u"  ' <== Wingdings3 character used to produce a right pointing solid triangle
            End If
            If e.Row.Cells(1).Text = "Potential Early" Then
                e.Row.Cells(1).Text = "t"  ' <== Wingdings3 character used to produce a left pointing solid triangle
                e.Row.Cells(1).ForeColor = Drawing.ColorTranslator.FromHtml("#FFD100")
            End If
            If e.Row.Cells(1).Text = "Potential Delay" Then
                e.Row.Cells(1).Text = "u"  ' <== Wingdings3 character used to produce a right pointing solid triangle
                e.Row.Cells(1).ForeColor = Drawing.ColorTranslator.FromHtml("#FFD100")
            End If
            If e.Row.Cells(1).Text = "No Delay" Then
                e.Row.Cells(1).Text = "u"  ' <== Wingdings3 character used to produce a right pointing solid triangle
                e.Row.Cells(1).ForeColor = Drawing.Color.Green
            End If
        End If

    End Sub

Open in new window


APS.NET code (added "Font-Names="Wingdings3"" to field I wanted to change the font):
...
                <asp:BoundField DataField="status_nm" HeaderText="Status">
                    <ItemStyle Width="3%"  Font-Names="Wingdings3" Font-Size="Medium"/>
                </asp:BoundField>
                <asp:BoundField DataField="status_desc" HeaderText="Description">
                    <ItemStyle Width="20%" />
                </asp:BoundField>
...

Open in new window


Results:
results2.PNG

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial