Reputation: 495
I'm working with Winforms and C#.
I have a datagridview I'm using for a cricket project. I need a column that will only accept numbers and a decimal value of 0 to 5.
EG:
10.0 (ok)
10.1 (ok)
10.2 (ok)
10.3 (ok)
10.4 (ok)
10.5 (ok)
10.6 (NOT OK) etc
I can set the cell format to N1
but that doesn't restrict the floating point part to just 0 to 5.
Does anyone have a nice solution for what I'm trying to achieve?
P.S - Sorry about the lack of code, but I'm typing this up quickly during my lunch break at work.
Upvotes: 1
Views: 549
Reputation: 119
This is validation, not formatting. Use a regular expression (C# Regex class) to check the input.
If you want the output as above, create a function which returns a string and the value as a parameter. Use that function in the gridview (e.g. text property of a label) and match against the regex ^\d*.[0-5]$
Upvotes: 3