formatting the size text in datagridview

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
jsira2003@yahoo.com
Posts: 112
Joined: Fri Apr 07, 2017 9:47 am

formatting the size text in datagridview

Post by jsira2003@yahoo.com » Mon Jun 03, 2019 10:58 am

I was looking for the text sizing option control in datagridview. I could not find one. Is this possible? If so how?

thanks,
John

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: formatting the size text in datagridview

Post by jvierra » Mon Jun 03, 2019 11:40 am

You can set that in the cell properties in the designer. Use the "DefaultCellStyle" property.

User avatar
jsira2003@yahoo.com
Posts: 112
Joined: Fri Apr 07, 2017 9:47 am

Re: formatting the size text in datagridview

Post by jsira2003@yahoo.com » Mon Jun 03, 2019 1:16 pm

and if I don't use the designer and want a text command is it something like this?:

datagridviewtable.defaultcellstyle.font.size = "12"

thanks,
John

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: formatting the size text in datagridview

Post by jvierra » Mon Jun 03, 2019 1:29 pm

No. You cannot set the size. You must create a font and set the "font" property to the new font.

Start by doing it in the designer and inspect the code that is produced to see how this is done.

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: formatting the size text in datagridview

Post by jvierra » Mon Jun 03, 2019 1:31 pm

When in doubt go to the documentation:

https://docs.microsoft.com/en-us/dotnet ... mework-4.8

User avatar
jsira2003@yahoo.com
Posts: 112
Joined: Fri Apr 07, 2017 9:47 am

Re: formatting the size text in datagridview

Post by jsira2003@yahoo.com » Mon Jun 03, 2019 8:05 pm

i used the cellstyle builder and it works fine. However when you save your program and re-open it, the cellstyle builder defaults back to the 14 point setting and I lose the font size I put in. In my view the cell style builder should maintain the font size I defined and I should not have to reset it in my datagridview with every build of my program.

I think this could be a bug!

John

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: formatting the size text in datagridview

Post by jvierra » Mon Jun 03, 2019 9:17 pm

I can't reproduce your issue. If I set the property in the designer and build the script it has the font and color that I set.

Locked