Results 1 to 11 of 11

Thread: [RESOLVED] [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Resolved [RESOLVED] [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    This code is to set Backcolor to the Header of DataGridView
    vb Code:
    1. Me.DataGridView3.ColumnHeadersDefaultCellStyle.BackColor = Color.White
    How to set a Size font and Bold to the text of ColumnHeaders

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    What other properties does ColumnheadersDefaultCellStyle have? Do you suppose one of them is a Font?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    I tried this but didn't succeed.
    vb Code:
    1. Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font.Bold = True
    2. Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font.Size = 15

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    Font objects are immutable, i.e. once you've created one you cannot change it. You have to create a new Font object with the attributes you desire and then assign that to the Font property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    What do you think about this:
    vb Code:
    1. Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
    2. Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = FontBold
    3.  
    4.  Dim FontSize As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font.Size, 15)
    5.  Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = FontSize

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    I think that assigning two different Fonts to the same property is pointless because the second one simply replaces the first so why assign the first at all?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    I can't understand what do you mean?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    You create a Font and assign it to the property. Then you create another Font and assign it to the property. At the end of that the property will be equal to the second Font, so what was the point of assigning the first Font?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    Do you mean I can assign tow properties in the same line?

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    No. I mean create one Font object and assign it to the Font property once. Just use whichever Font constructor that allows you to specify all the property values you need. The Font class has 13 constructors. It shouldn't be too hard to find one that suits your needs.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] How to set a Size font and Bold to the text of ColumnHeaders of DGV

    I think you mean like this:
    vb Code:
    1. Dim FontDefault As New Font("tahoma", 8, FontStyle.Regular)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width