Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i have a datagridview in which we enter prices in cells..
user's prices doesnt not have more than 2 digits after decimal point..
for example his prices all are like 9.99/99.99/999.99/9999.99/99999.99/999999.99 .....
but not like 9.999/9.9999/9.99999

i written a code in which we enter more than two digits, after cell leave it was recurring and displaying two digits only like 8.89999 it will display 8.90 after cell leave as it will recur.

but i dont want recurring. it should restrict entering more than two digits.
like

C#
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
            {
                e.Handled = true;
            }

in this code it will restrict entering alphabetic letters..
like this i want a code which should restrict only two digits after decimal point.....

Thanks in Advance
Posted
Comments
Michael_Davies 4-Apr-15 6:22am    
Edit the columns for your DG, select the column you want to change, open the DefaultCellStyle dialog, open the Format dialog, change it to Numeric and set the decimal places as you wish.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900