Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

.NET changing the font of the text in a DataGridView

Posted on 2012-08-14
8
Medium Priority
?
372 Views
Last Modified: 2012-09-16
I am trying to reduce the font size in the DataGridView for all the colomns
0
Comment
Question by:prowebinteractiveinc
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:nkish
ID: 38296128
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
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 38296191
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38296219
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 29

Expert Comment

by:sammySeltzer
ID: 38296267
If it is windows as TheLearnedOne indicated, then this link would do:

http://stackoverflow.com/questions/64041/winform-datagridview-font-size
0
 

Author Comment

by:prowebinteractiveinc
ID: 38307283
Im working with windows forms
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38307991
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
 

Author Comment

by:prowebinteractiveinc
ID: 38391368
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 38391388
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question