format for Textbox and DatagridView

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 8 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

format for Textbox and DatagridView

Post by jramon.r@tv3.cat »

My Powershell Studio runs in a Windows 2008 R2, 64 bits.

I'm trying to show data from an access table in a DataGridView. I'd like to show number data with thousand punctuation. I found the property CellStyleBuilder and here I changed the Format to Numeric. The result is that it shows one row good with the appropiate punctuation and one without the punctuation, it alternates one good and one bad. What's happening?

In a similar situation I show the same data in a TextBox, and here I don't Know how I can change the format to Numeric with the thousand punctuation, or if it'd be better use another control.

Thank you
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format for Textbox and DatagridView

Post by jvierra »

You need to post an example PSF file showing the issue.

For a textbox that is formatted you need to use the MaskedTextBox control.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format for Textbox and DatagridView

Post by jvierra »

Take a look at this demo. It shows how to format the numbers in a column.
Attachments
Demo-DGVFrmatting.psf
(15.98 KiB) Downloaded 236 times
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

Re: format for Textbox and DatagridView

Post by jramon.r@tv3.cat »

Finally I've found the solution. In the DataGridView I was modifying the property AlternatingRowsDefaultCellStyle, this is the cause it showed me just odd rows good.

With the MaskedTextBox I don't understand it very well, how can I show thousands, because sometimes it can be a number like 1.000 but sometimes it can be 10.000, so the thousand punctuation is not always in the same place, do you know how can I do it?

Thank you
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format for Textbox and DatagridView

Post by jvierra »

There is a pre-defined mask for numeric display.

'{0:N2}' -f 1Mb

Select the N2 mask.

Unfortunately you will have to programmatically set the display as there is no mask for that in standard forms.
User avatar
jramon.r@tv3.cat
Posts: 25
Last visit: Tue Jan 11, 2022 4:23 am

Re: format for Textbox and DatagridView

Post by jramon.r@tv3.cat »

Ok thanks.
This topic is 8 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked