.NET changing the font of the text in a DataGridView

I am trying to reduce the font size in the DataGridView for all the colomns
prowebinteractiveincAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
The CellFormatting event is a good place to apply custom styles, based on different criteria.

Color DataGridView Cells Based On Data  
http://www.getdotnetcode.com/gdncstore/free/ColorDataGridViewCellsBasedOnData/ColorDataGridViewCellsBasedOnData.htm

Private Sub customerDataGridView_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles customerDataGridView.CellFormatting

    ' If the column being formatted is the column named 'Status' ..
    If Me.customerDataGridView.Columns(e.ColumnIndex).Name = "Status" Then
        If e.Value IsNot Nothing Then
           ' If the value of the cell is "Inactive" AND this form's inactiveCustomersCheckBox control is checked..
            If e.Value.ToString = "Inactive" And Me.inactiveCustomersCheckBox.Checked Then
                ' Set the BackColor of the cell to yellow.
                e.CellStyle.BackColor = Color.Yellow
            End If
        End If
    End If

    ' If the column being formatted is the column named 'LastOrderDate'..
    If Me.customerDataGridView.Columns(e.ColumnIndex).Name = "LastOrderDate" Then
        If e.Value IsNot Nothing Then
            ' If LastOrderDate was more than 30 days ago AND this form's ordersOverdueCheckBox control is checked..
             If Date.Now.Subtract(CType(e.Value, Date)).Days > 30 And Me.orderOverdueCheckBox.Checked Then
                ' Set the BackColor of the cell to yellow-green.
                e.CellStyle.BackColor = Color.YellowGreen
            End If
        End If
    End If
End Sub

Open in new window

0
 
nkishCommented:
You can create an element in your CSS with the font properties (including the size) and then reference the element in the DataGridView control (using the CssClass property).
0
 
sammySeltzerCommented:
Unless I misunderstand your question, all you would need to do is:

<asp:GridView ID="gridview1" runat="server" font-size="12"... />

All you would need is change font-size to whatever you need
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Bob LearnedCommented:
Names for grids can be confusing without more detail, as DataGridView is typically a Windows Forms name, and GridView is typically an ASP.NET name.
0
 
sammySeltzerCommented:
If it is windows as TheLearnedOne indicated, then this link would do:

http://stackoverflow.com/questions/64041/winform-datagridview-font-size
0
 
prowebinteractiveincAuthor Commented:
Im working with windows forms
0
 
Bob LearnedCommented:
If you set the Font property for the DataGridView, then it should apply to all the elements (headers, cells, etc.).  If you cell the Font property for a column, then it should just apply to the cells.

You can also handle the CellFormatting or CellPainting event handlers, and do special formatting for the DataGridView.
0
 
prowebinteractiveincAuthor Commented:
but what about specific rows at a time example

I have a list of invoices invoices 0-29 days old are black, 30-59 are blue, 60-89 yellow, 90+ red
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.