none
Font for DataGridView cells

    Question

  • I am stumpped, anyone know What am I doing wrong to change the font used by Datagridview Cells and Cell Height?
    See Screen Shot Attached.
    
    
    
      Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            dgv.ColumnCount = 4
    
            With dgv.ColumnHeadersDefaultCellStyle
                .BackColor = Color.Khaki
                .ForeColor = Color.White
                .Font = New Font(dgv.Font, FontStyle.Bold)
            End With
            With dgv
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250) 
                .AutoSizeRowsMode =
                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"
                .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .Columns(0).DefaultCellStyle.Font =
                New Font(Me.dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With
            Dim Header_FontSize As New Font(dgv.ColumnHeadersDefaultCellStyle.Font.Size, 12)
            Me.dgv.ColumnHeadersDefaultCellStyle.Font = Header_FontSize
            '***********************************************************
            Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.Size, 12)
            dgv.DefaultCellStyle.Font = Column_FontSize
            '***********************************************************
           
        End Sub


    Charlie Soroka

    Wednesday, March 7, 2018 4:02 PM

Answers

  • Hi

    Maybe this correction will help.

    	' changed/added .FontFamily as .Size invalid
    	Dim Header_FontSize As New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
    	Me.dgv.ColumnHeadersDefaultCellStyle.Font = Header_FontSize
    	'******************************
    	' changed/added .FontFamily as .Size invalid
    	Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.FontFamily, 12)
    	dgv.DefaultCellStyle.Font = Column_FontSize
    	'******************************
    
    if you put Option Strict On and Option Explicit On at the top of your code, then you would have caught those mistakes.


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Wednesday, March 7, 2018 4:49 PM
  • Hi

    Here is your code with a few changes so that the Header styles you specified are made visible. I put everything into the With dgv block. (there is also a few lines at end which are only for my testing and should be removed)

    	With dgv
    	  .ColumnCount = 4
    	  .Name = "Stock Quote Grid"
    	  .Location = New Point(8, 8)
    	  .Size = New Size(500, 250)
    	  .AutoSizeRowsMode =
    			 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    	  .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    	  .CellBorderStyle = DataGridViewCellBorderStyle.Single
    	  .DefaultCellStyle.ForeColor = Color.Black
    
    	  ' added this line
    	  .EnableHeadersVisualStyles = False
    
    	  ' inserted these lines (deleted from below)
    	  .DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font.FontFamily, 12)
    	  With .ColumnHeadersDefaultCellStyle
    		.BackColor = Color.Khaki
    		.ForeColor = Color.Red
    		.Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
    	  End With
    
    	  .BackgroundColor = Color.AliceBlue
    	  .GridColor = Color.Black
    
    	  .RowHeadersVisible = False
    	  .Columns(0).Width = 250
    	  .Columns(0).Name = "Name"
    	  .Columns(1).Width = 90
    	  .Columns(1).Name = "Date"
    	  .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
    	  .Columns(2).Width = 100
    	  .Columns(2).Name = "Amount"
    	  .Columns(3).Width = 55
    	  .Columns(3).Name = "ID"
    	  .Columns(0).DefaultCellStyle.Font =
    			New Font(dgv.DefaultCellStyle.Font, FontStyle.Italic)
    	  .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    	  .MultiSelect = True
    	  .Dock = DockStyle.Fill
    
    	  'my addition just for testing
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	End With


    Regards Les, Livingston, Scotland

    Wednesday, March 7, 2018 5:19 PM
  • Thanks for your reply, Revised code and new screen shot attached.
    The Dgv.defaultcellstyle.font for some reason did not work? 
    
    Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            With dgv
                .ColumnCount = 4
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250) ' 500, 250
                .AutoSizeRowsMode =
                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                ' added this line
                .EnableHeadersVisualStyles = False
    
                ' inserted these lines (deleted from below)
                .DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font.FontFamily, 12)
                With .ColumnHeadersDefaultCellStyle
                    .BackColor = Color.Khaki
                    .ForeColor = Color.Red
                    .Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
                End With
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"
                .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .Columns(0).DefaultCellStyle.Font =
                New Font(Me.dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With
    
            'Me.WindowState = FormWindowState.Maximized
        End Sub
    
    


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Wednesday, March 7, 2018 9:45 PM
  •  So,  what is not working the way you expect?  I see the header text is cut off and I also see that the first column is not Italic.  Are they the problems?

     After changing a couple errors in your code (posted below),  it looks like the image below,  is that the way you want it to look?

        Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            dgv.ColumnCount = 4

            With dgv.ColumnHeadersDefaultCellStyle
                .BackColor = Color.Khaki
                .ForeColor = Color.White
                .Font = New Font(dgv.Font, FontStyle.Bold)
            End With
            With dgv
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250)
                .AutoSizeRowsMode =
                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"

                '"C2" is a format for displaying currency like displaying 22.5 as $22.50, not a Date. Perhaps you want this for the Amount column instead.
                .Columns(2).DefaultCellStyle.Format = "c2"

                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .Columns(0).DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With

            Dim Header_FontSize As New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12) 'fixed this
            Me.dgv.ColumnHeadersDefaultCellStyle.Font = Header_FontSize
            '***********************************************************

            Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.FontFamily, 12) 'fixed this
            dgv.DefaultCellStyle.Font = Column_FontSize
            '***********************************************************
        End Sub
      

     After adding a DataGridView to a form (no changes) and using the code above,  this is what I get.

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Thursday, March 8, 2018 12:15 AM
    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 12:13 AM
  • The DefaultCellStyle Font is smaller than the HeadersDefaultCellStyle. Font.  Is there a way to make

    the DefaultCellStyle Font  the same size?


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 1:41 AM
  • Mabe you need to address each column with something like this, what do you think?
        Dim font As New Font(
                DGV.DefaultCellStyle.Font.FontFamily, 12, FontStyle.Bold)
            Try
                DGV.Columns(1).DefaultCellStyle.Font = font
            Finally
                font.Dispose()
            End Try

    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 2:35 AM
  • The DefaultCellStyle Font is smaller than the HeadersDefaultCellStyle. Font.  Is there a way to make

    the DefaultCellStyle Font  the same size?


    Charlie Soroka

    Hi socrokateam,

    You said that the DataGridview.columns(0) font is smaller then the headersdefaultCellStyle font? Because you have seted three font styles,

    For DataGridview.column(0):

     Dim column1Fontsize As New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
                .Columns(0).DefaultCellStyle.Font = column1Fontsize
     

    The font is Name=Microsoft Sans Serif, Size=8.25

    For DataGridView1.DefaultCellStyle.Font:

     Dim Column_FontSize As New Font(DataGridView1.DefaultCellStyle.Font.FontFamily, 12) 'fixed this
            DataGridView1.DefaultCellStyle.Font = Column_FontSize

    The font is Name=Microsoft Sans Serif, Size=12, Units=3

    For DataGridView1.ColumnHeadersDefaultCellStyle.Font:

    Dim Header_FontSize As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12) 'fixed this
            Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = Header_FontSize

    The font is Name=Microsoft Sans Serif, Size=12, Units=3

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 6:20 AM
    Moderator
  • I add the code to set column 1 to DefaultCellStyle font of 12.  See screen dump, somewhere in the code
    must be preventing executing of Defaultcellstyle code. Code for Changing format to C2 
    (   .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date ) works fine. Still Stumped?
    
     Private Sub SetupDataGridView()
    
            Me.Controls.Add(dgv)
    
            With dgv
                .ColumnCount = 4
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
    
                .AutoSizeRowsMode =
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
    
                ' added this line
                .EnableHeadersVisualStyles = False
    
                With .ColumnHeadersDefaultCellStyle
                    .BackColor = Color.Khaki
                    .ForeColor = Color.Red
                    .Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
                End With
                dgv.RowHeadersDefaultCellStyle.SelectionForeColor = Color.Black
                ' New Code to increase size of font for column 1 ** Does Not Change **
                Dim font1 As New Font(.DefaultCellStyle.Font.FontFamily,
                                      12, FontStyle.Bold) ' DefaultCellStyle 
                Try
                    .Columns(1).DefaultCellStyle.Font = font1
                Finally
                    font1.Dispose()
                End Try
    
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"
                .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With
    
            'Me.WindowState = FormWindowState.Maximized
        End Sub
    


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 9:41 PM
  • Hi

    Please do not put the text of your post in the code block - as you can see, the text doesn't wrap correctly if you do that. Instead, add your text to the editor directly - only put the code in the code block.


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 10:55 PM
  • Sorry, Will do

    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Friday, March 9, 2018 12:03 AM
  • The DefaultCellStyle Font is smaller than the HeadersDefaultCellStyle. Font.  Is there a way to make

    the DefaultCellStyle Font  the same size?


    Charlie Soroka

     Perhaps the example below does what you want.  Basically I have only changed the order in which the Fonts are being set.  This makes all the cells have the same size font as the header font.  You also seemed to be setting the ColumnHeadersDefaultCellStyle font twice,  to two different fonts,  once at the start of the sub and once at the end of the sub.  I eliminated the second one and changed the first one to include the size 12 in the font constructor.

        Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            dgv.ColumnCount = 4
    
            Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.FontFamily, 12) 'fixed this
            dgv.DefaultCellStyle.Font = Column_FontSize
    
            With dgv.ColumnHeadersDefaultCellStyle
                .BackColor = Color.Khaki
                .ForeColor = Color.White
                .Font = New Font(dgv.Font.FontFamily, 12, FontStyle.Bold)
            End With
    
            With dgv
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250)
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
    
                .Columns(0).DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
    
                .Columns(1).DefaultCellStyle.Format = "d" 'format for a Short date
    .Columns(1).Width = 90 .Columns(1).Name = "Date" .Columns(2).DefaultCellStyle.Format = "c2" 'format for currency .Columns(2).Width = 100 .Columns(2).Name = "Amount" .Columns(3).Width = 55 .Columns(3).Name = "ID" End With End Sub

     

     This is now what it looks like,  all the same size font but,  Bold in the headers and Italic in the Name column.

     

     Also,  if you look at the  Standard Date and Time Format Strings,  you will see there is not a "C" formatting string for a Date type.  However,  as I said before,  there is one for formatting a numeric data as currency as shown here -> Standard Numeric Format Strings.


    If you say it can`t be done then i`ll try it

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 12:09 AM
  • Hi

    Here is a version showing that the Font sizes do in fact work OK. I used extra large in example to prove it.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	SetupDataGridView()
      End Sub
      Private Sub SetupDataGridView()
    	With dgv
    	  .ColumnCount = 4
    	  .Name = "Stock Quote Grid"
    	  .Location = New Point(8, 8)
    
    	  .AutoSizeRowsMode =
    	  DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    	  .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    	  .CellBorderStyle = DataGridViewCellBorderStyle.Single
    	  .DefaultCellStyle.ForeColor = Color.Black
    	  .DefaultCellStyle.BackColor = Color.Beige
    
    	  .EnableHeadersVisualStyles = False
    
    	  With .ColumnHeadersDefaultCellStyle
    		.BackColor = Color.Yellow
    		.ForeColor = Color.Red
    		.Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12, FontStyle.Bold)
    	  End With
    
    	  ' WHY! you do not show the row headers? 7 lines below!
    	  ' .RowHeadersDefaultCellStyle.SelectionForeColor = Color.Black
    
    	  ' te3sting with extra large font to prove it does work!
    	  .Columns(1).DefaultCellStyle.Font = New Font(.DefaultCellStyle.Font.FontFamily, 20, FontStyle.Bold)
    
    	  .BackgroundColor = Color.AliceBlue
    	  .GridColor = Color.Black
    	  .RowHeadersVisible = False
    	  .Columns(0).Width = 250
    	  .Columns(0).Name = "Name"
    	  .Columns(1).Name = "Date"
    
    	  ' my change for testing font size
    	  .Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    
    	  ' C2 is not a Date format
    	  .Columns(1).DefaultCellStyle.Format = "dd MM yyyy" ' Format for Date
    
    	  .Columns(2).Width = 100
    	  .Columns(2).Name = "Amount"
    	  .Columns(3).Width = 55
    	  .Columns(3).Name = "ID"
    	  .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    	  .MultiSelect = True
    	  .Dock = DockStyle.Fill
    
    	  'my addition just for testing
    	  .Rows.Add("freddy1", Now.AddDays(11), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(111), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(12), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(121), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(112), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(21), 1.23, 43.25)
    	End With
      End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 12:10 AM
  • I added your code for testing and did add ( PrivateWithEventsdgv AsNewDataGridView

    I get a BLANK SCREEN, what am I missing


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 2:47 AM
  • I added your code for testing and did add ( PrivateWithEventsdgv AsNewDataGridView

    I get a BLANK SCREEN, what am I missing


    Charlie Soroka


     Did you look at my last example?  If you want all the cells to have the same font size but want one column to be Italic,  that is what it does.  I believe that is what you said the problem was.

    If you say it can`t be done then i`ll try it

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 3:02 AM
  • I added your code for testing and did add ( PrivateWithEventsdgv AsNewDataGridView

    I get a BLANK SCREEN, what am I missing


    Charlie Soroka

    Hi

    You probably don't have the 'Controls.Add(dgv)' at the bottom of the code. See:

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private WithEvents dgv As New DataGridView
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	SetupDataGridView()
      End Sub
      Private Sub SetupDataGridView()
    	With dgv
    	  .ColumnCount = 4
    	  .Name = "Stock Quote Grid"
    	  .Location = New Point(8, 8)
    
    	  .AutoSizeRowsMode =
    	  DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    	  .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    	  .CellBorderStyle = DataGridViewCellBorderStyle.Single
    	  .DefaultCellStyle.ForeColor = Color.Black
    	  .DefaultCellStyle.BackColor = Color.Beige
    
    	  .EnableHeadersVisualStyles = False
    
    	  With .ColumnHeadersDefaultCellStyle
    		.BackColor = Color.Yellow
    		.ForeColor = Color.Red
    		.Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12, FontStyle.Bold)
    	  End With
    
    	  ' te3sting with extra large font to prove it does work!
    	  .Columns(1).DefaultCellStyle.Font = New Font(.DefaultCellStyle.Font.FontFamily, 20, FontStyle.Bold)
    
    	  .BackgroundColor = Color.AliceBlue
    	  .GridColor = Color.Black
    	  .RowHeadersVisible = False
    	  .Columns(0).Width = 250
    	  .Columns(0).Name = "Name"
    	  .Columns(1).Name = "Date"
    
    	  ' my change for testing font size
    	  .Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    
    	  ' C2 is not a Date format
    	  .Columns(1).DefaultCellStyle.Format = "dd MM yyyy" ' Format for Date
    
    	  .Columns(2).Width = 100
    	  .Columns(2).Name = "Amount"
    	  .Columns(3).Width = 55
    	  .Columns(3).Name = "ID"
    	  .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    	  .MultiSelect = True
    	  .Dock = DockStyle.Fill
    
    	  'my addition just for testing
    	  .Rows.Add("freddy1", Now.AddDays(11), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(111), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(12), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(121), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(112), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(21), 1.23, 43.25)
    	End With
    	Controls.Add(dgv)
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 1:03 PM
  • Thanks for your help & code sample, I can make this work in my application.


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 7:10 PM

All replies

  • Hi

    Maybe this correction will help.

    	' changed/added .FontFamily as .Size invalid
    	Dim Header_FontSize As New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
    	Me.dgv.ColumnHeadersDefaultCellStyle.Font = Header_FontSize
    	'******************************
    	' changed/added .FontFamily as .Size invalid
    	Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.FontFamily, 12)
    	dgv.DefaultCellStyle.Font = Column_FontSize
    	'******************************
    
    if you put Option Strict On and Option Explicit On at the top of your code, then you would have caught those mistakes.


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Wednesday, March 7, 2018 4:49 PM
  • Hi

    Here is your code with a few changes so that the Header styles you specified are made visible. I put everything into the With dgv block. (there is also a few lines at end which are only for my testing and should be removed)

    	With dgv
    	  .ColumnCount = 4
    	  .Name = "Stock Quote Grid"
    	  .Location = New Point(8, 8)
    	  .Size = New Size(500, 250)
    	  .AutoSizeRowsMode =
    			 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    	  .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    	  .CellBorderStyle = DataGridViewCellBorderStyle.Single
    	  .DefaultCellStyle.ForeColor = Color.Black
    
    	  ' added this line
    	  .EnableHeadersVisualStyles = False
    
    	  ' inserted these lines (deleted from below)
    	  .DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font.FontFamily, 12)
    	  With .ColumnHeadersDefaultCellStyle
    		.BackColor = Color.Khaki
    		.ForeColor = Color.Red
    		.Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
    	  End With
    
    	  .BackgroundColor = Color.AliceBlue
    	  .GridColor = Color.Black
    
    	  .RowHeadersVisible = False
    	  .Columns(0).Width = 250
    	  .Columns(0).Name = "Name"
    	  .Columns(1).Width = 90
    	  .Columns(1).Name = "Date"
    	  .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
    	  .Columns(2).Width = 100
    	  .Columns(2).Name = "Amount"
    	  .Columns(3).Width = 55
    	  .Columns(3).Name = "ID"
    	  .Columns(0).DefaultCellStyle.Font =
    			New Font(dgv.DefaultCellStyle.Font, FontStyle.Italic)
    	  .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    	  .MultiSelect = True
    	  .Dock = DockStyle.Fill
    
    	  'my addition just for testing
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	  .Rows.Add("freddy1", "Hello All", 1.23, 43.25)
    	End With


    Regards Les, Livingston, Scotland

    Wednesday, March 7, 2018 5:19 PM
  • Thanks for your reply, Revised code and new screen shot attached.
    The Dgv.defaultcellstyle.font for some reason did not work? 
    
    Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            With dgv
                .ColumnCount = 4
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250) ' 500, 250
                .AutoSizeRowsMode =
                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                ' added this line
                .EnableHeadersVisualStyles = False
    
                ' inserted these lines (deleted from below)
                .DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font.FontFamily, 12)
                With .ColumnHeadersDefaultCellStyle
                    .BackColor = Color.Khaki
                    .ForeColor = Color.Red
                    .Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
                End With
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"
                .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .Columns(0).DefaultCellStyle.Font =
                New Font(Me.dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With
    
            'Me.WindowState = FormWindowState.Maximized
        End Sub
    
    


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Wednesday, March 7, 2018 9:45 PM
  •  So,  what is not working the way you expect?  I see the header text is cut off and I also see that the first column is not Italic.  Are they the problems?

     After changing a couple errors in your code (posted below),  it looks like the image below,  is that the way you want it to look?

        Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            dgv.ColumnCount = 4

            With dgv.ColumnHeadersDefaultCellStyle
                .BackColor = Color.Khaki
                .ForeColor = Color.White
                .Font = New Font(dgv.Font, FontStyle.Bold)
            End With
            With dgv
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250)
                .AutoSizeRowsMode =
                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"

                '"C2" is a format for displaying currency like displaying 22.5 as $22.50, not a Date. Perhaps you want this for the Amount column instead.
                .Columns(2).DefaultCellStyle.Format = "c2"

                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .Columns(0).DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With

            Dim Header_FontSize As New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12) 'fixed this
            Me.dgv.ColumnHeadersDefaultCellStyle.Font = Header_FontSize
            '***********************************************************

            Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.FontFamily, 12) 'fixed this
            dgv.DefaultCellStyle.Font = Column_FontSize
            '***********************************************************
        End Sub
      

     After adding a DataGridView to a form (no changes) and using the code above,  this is what I get.

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Thursday, March 8, 2018 12:15 AM
    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 12:13 AM
  • The DefaultCellStyle Font is smaller than the HeadersDefaultCellStyle. Font.  Is there a way to make

    the DefaultCellStyle Font  the same size?


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 1:41 AM
  • Mabe you need to address each column with something like this, what do you think?
        Dim font As New Font(
                DGV.DefaultCellStyle.Font.FontFamily, 12, FontStyle.Bold)
            Try
                DGV.Columns(1).DefaultCellStyle.Font = font
            Finally
                font.Dispose()
            End Try

    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 2:35 AM
  • The DefaultCellStyle Font is smaller than the HeadersDefaultCellStyle. Font.  Is there a way to make

    the DefaultCellStyle Font  the same size?


    Charlie Soroka

    Hi socrokateam,

    You said that the DataGridview.columns(0) font is smaller then the headersdefaultCellStyle font? Because you have seted three font styles,

    For DataGridview.column(0):

     Dim column1Fontsize As New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Italic)
                .Columns(0).DefaultCellStyle.Font = column1Fontsize
     

    The font is Name=Microsoft Sans Serif, Size=8.25

    For DataGridView1.DefaultCellStyle.Font:

     Dim Column_FontSize As New Font(DataGridView1.DefaultCellStyle.Font.FontFamily, 12) 'fixed this
            DataGridView1.DefaultCellStyle.Font = Column_FontSize

    The font is Name=Microsoft Sans Serif, Size=12, Units=3

    For DataGridView1.ColumnHeadersDefaultCellStyle.Font:

    Dim Header_FontSize As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12) 'fixed this
            Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = Header_FontSize

    The font is Name=Microsoft Sans Serif, Size=12, Units=3

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 6:20 AM
    Moderator
  • I add the code to set column 1 to DefaultCellStyle font of 12.  See screen dump, somewhere in the code
    must be preventing executing of Defaultcellstyle code. Code for Changing format to C2 
    (   .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date ) works fine. Still Stumped?
    
     Private Sub SetupDataGridView()
    
            Me.Controls.Add(dgv)
    
            With dgv
                .ColumnCount = 4
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
    
                .AutoSizeRowsMode =
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
    
                ' added this line
                .EnableHeadersVisualStyles = False
    
                With .ColumnHeadersDefaultCellStyle
                    .BackColor = Color.Khaki
                    .ForeColor = Color.Red
                    .Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12)
                End With
                dgv.RowHeadersDefaultCellStyle.SelectionForeColor = Color.Black
                ' New Code to increase size of font for column 1 ** Does Not Change **
                Dim font1 As New Font(.DefaultCellStyle.Font.FontFamily,
                                      12, FontStyle.Bold) ' DefaultCellStyle 
                Try
                    .Columns(1).DefaultCellStyle.Font = font1
                Finally
                    font1.Dispose()
                End Try
    
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
                .Columns(1).Width = 90
                .Columns(1).Name = "Date"
                .Columns(1).DefaultCellStyle.Format = "c2" ' Format for Date
                .Columns(2).Width = 100
                .Columns(2).Name = "Amount"
                .Columns(3).Width = 55
                .Columns(3).Name = "ID"
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
            End With
    
            'Me.WindowState = FormWindowState.Maximized
        End Sub
    


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 9:41 PM
  • Hi

    Please do not put the text of your post in the code block - as you can see, the text doesn't wrap correctly if you do that. Instead, add your text to the editor directly - only put the code in the code block.


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Thursday, March 8, 2018 10:55 PM
  • Sorry, Will do

    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:11 PM
    Friday, March 9, 2018 12:03 AM
  • The DefaultCellStyle Font is smaller than the HeadersDefaultCellStyle. Font.  Is there a way to make

    the DefaultCellStyle Font  the same size?


    Charlie Soroka

     Perhaps the example below does what you want.  Basically I have only changed the order in which the Fonts are being set.  This makes all the cells have the same size font as the header font.  You also seemed to be setting the ColumnHeadersDefaultCellStyle font twice,  to two different fonts,  once at the start of the sub and once at the end of the sub.  I eliminated the second one and changed the first one to include the size 12 in the font constructor.

        Private Sub SetupDataGridView()
            Me.Controls.Add(dgv)
            dgv.ColumnCount = 4
    
            Dim Column_FontSize As New Font(dgv.DefaultCellStyle.Font.FontFamily, 12) 'fixed this
            dgv.DefaultCellStyle.Font = Column_FontSize
    
            With dgv.ColumnHeadersDefaultCellStyle
                .BackColor = Color.Khaki
                .ForeColor = Color.White
                .Font = New Font(dgv.Font.FontFamily, 12, FontStyle.Bold)
            End With
    
            With dgv
                .Name = "Stock Quote Grid"
                .Location = New Point(8, 8)
                .Size = New Size(500, 250)
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
                .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                .CellBorderStyle = DataGridViewCellBorderStyle.Single
                .DefaultCellStyle.ForeColor = Color.Black
                .BackgroundColor = Color.AliceBlue
                .GridColor = Color.Black
                .RowHeadersVisible = False
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .MultiSelect = True
                .Dock = DockStyle.Fill
    
                .Columns(0).DefaultCellStyle.Font = New Font(dgv.DefaultCellStyle.Font, FontStyle.Italic)
                .Columns(0).Width = 250
                .Columns(0).Name = "Name"
    
                .Columns(1).DefaultCellStyle.Format = "d" 'format for a Short date
    .Columns(1).Width = 90 .Columns(1).Name = "Date" .Columns(2).DefaultCellStyle.Format = "c2" 'format for currency .Columns(2).Width = 100 .Columns(2).Name = "Amount" .Columns(3).Width = 55 .Columns(3).Name = "ID" End With End Sub

     

     This is now what it looks like,  all the same size font but,  Bold in the headers and Italic in the Name column.

     

     Also,  if you look at the  Standard Date and Time Format Strings,  you will see there is not a "C" formatting string for a Date type.  However,  as I said before,  there is one for formatting a numeric data as currency as shown here -> Standard Numeric Format Strings.


    If you say it can`t be done then i`ll try it

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 12:09 AM
  • Hi

    Here is a version showing that the Font sizes do in fact work OK. I used extra large in example to prove it.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	SetupDataGridView()
      End Sub
      Private Sub SetupDataGridView()
    	With dgv
    	  .ColumnCount = 4
    	  .Name = "Stock Quote Grid"
    	  .Location = New Point(8, 8)
    
    	  .AutoSizeRowsMode =
    	  DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    	  .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    	  .CellBorderStyle = DataGridViewCellBorderStyle.Single
    	  .DefaultCellStyle.ForeColor = Color.Black
    	  .DefaultCellStyle.BackColor = Color.Beige
    
    	  .EnableHeadersVisualStyles = False
    
    	  With .ColumnHeadersDefaultCellStyle
    		.BackColor = Color.Yellow
    		.ForeColor = Color.Red
    		.Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12, FontStyle.Bold)
    	  End With
    
    	  ' WHY! you do not show the row headers? 7 lines below!
    	  ' .RowHeadersDefaultCellStyle.SelectionForeColor = Color.Black
    
    	  ' te3sting with extra large font to prove it does work!
    	  .Columns(1).DefaultCellStyle.Font = New Font(.DefaultCellStyle.Font.FontFamily, 20, FontStyle.Bold)
    
    	  .BackgroundColor = Color.AliceBlue
    	  .GridColor = Color.Black
    	  .RowHeadersVisible = False
    	  .Columns(0).Width = 250
    	  .Columns(0).Name = "Name"
    	  .Columns(1).Name = "Date"
    
    	  ' my change for testing font size
    	  .Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    
    	  ' C2 is not a Date format
    	  .Columns(1).DefaultCellStyle.Format = "dd MM yyyy" ' Format for Date
    
    	  .Columns(2).Width = 100
    	  .Columns(2).Name = "Amount"
    	  .Columns(3).Width = 55
    	  .Columns(3).Name = "ID"
    	  .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    	  .MultiSelect = True
    	  .Dock = DockStyle.Fill
    
    	  'my addition just for testing
    	  .Rows.Add("freddy1", Now.AddDays(11), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(111), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(12), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(121), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(112), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(21), 1.23, 43.25)
    	End With
      End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 12:10 AM
  • I added your code for testing and did add ( PrivateWithEventsdgv AsNewDataGridView

    I get a BLANK SCREEN, what am I missing


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 2:47 AM
  • I added your code for testing and did add ( PrivateWithEventsdgv AsNewDataGridView

    I get a BLANK SCREEN, what am I missing


    Charlie Soroka


     Did you look at my last example?  If you want all the cells to have the same font size but want one column to be Italic,  that is what it does.  I believe that is what you said the problem was.

    If you say it can`t be done then i`ll try it

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 3:02 AM
  • I added your code for testing and did add ( PrivateWithEventsdgv AsNewDataGridView

    I get a BLANK SCREEN, what am I missing


    Charlie Soroka

    Hi

    You probably don't have the 'Controls.Add(dgv)' at the bottom of the code. See:

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private WithEvents dgv As New DataGridView
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	SetupDataGridView()
      End Sub
      Private Sub SetupDataGridView()
    	With dgv
    	  .ColumnCount = 4
    	  .Name = "Stock Quote Grid"
    	  .Location = New Point(8, 8)
    
    	  .AutoSizeRowsMode =
    	  DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    	  .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
    	  .CellBorderStyle = DataGridViewCellBorderStyle.Single
    	  .DefaultCellStyle.ForeColor = Color.Black
    	  .DefaultCellStyle.BackColor = Color.Beige
    
    	  .EnableHeadersVisualStyles = False
    
    	  With .ColumnHeadersDefaultCellStyle
    		.BackColor = Color.Yellow
    		.ForeColor = Color.Red
    		.Font = New Font(dgv.ColumnHeadersDefaultCellStyle.Font.FontFamily, 12, FontStyle.Bold)
    	  End With
    
    	  ' te3sting with extra large font to prove it does work!
    	  .Columns(1).DefaultCellStyle.Font = New Font(.DefaultCellStyle.Font.FontFamily, 20, FontStyle.Bold)
    
    	  .BackgroundColor = Color.AliceBlue
    	  .GridColor = Color.Black
    	  .RowHeadersVisible = False
    	  .Columns(0).Width = 250
    	  .Columns(0).Name = "Name"
    	  .Columns(1).Name = "Date"
    
    	  ' my change for testing font size
    	  .Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    
    	  ' C2 is not a Date format
    	  .Columns(1).DefaultCellStyle.Format = "dd MM yyyy" ' Format for Date
    
    	  .Columns(2).Width = 100
    	  .Columns(2).Name = "Amount"
    	  .Columns(3).Width = 55
    	  .Columns(3).Name = "ID"
    	  .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    	  .MultiSelect = True
    	  .Dock = DockStyle.Fill
    
    	  'my addition just for testing
    	  .Rows.Add("freddy1", Now.AddDays(11), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(111), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(12), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(121), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(112), 1.23, 43.25)
    	  .Rows.Add("freddy1", Now.AddDays(21), 1.23, 43.25)
    	End With
    	Controls.Add(dgv)
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 1:03 PM
  • Thanks for your help & code sample, I can make this work in my application.


    Charlie Soroka

    • Marked as answer by sorokateam Friday, March 9, 2018 7:12 PM
    Friday, March 9, 2018 7:10 PM