Decimal Places on Text Boxes VS C# 2008

Apparently formats that work for data grid views do not work for text boxes. The fields I have at the bottom of this screen are masked text boxes. All I want is the number field to be displayed w/o any decimal places, the two numeric fields to have two decimal places and the percent number to be displayed as 999.99%. What is the correct way to accomplish this? Are Masked Text boxes correct or will a text box do? Should I do the conversion in the SQL select statement? The bottom numbers are sums or averages of what is displayed in the data grid view.
GPDataSet = new System.Data.DataSet();
                GPDataSet.CaseSensitive = false;

                GPCommand = new System.Data.SqlClient.SqlCommand();
                GPCommand.Connection = GPConnection;

                GPCommand.CommandText = "select sum(convert(int, sol.quantity)) AS 'TotalQTY',sum(sol.xtndprce) AS 'TotalPrice',sum(CASE WHEN pop.ponumber is NULL THEN sol.unitcost * sol.quantity ELSE pop.unitcost * sol.quantity END) as 'TotalCost',avg(CASE WHEN pop.unitcost* sol.quantity = 0 or pop.ponumber is NULL THEN CASE WHEN sol.extdcost = 0 THEN 0 ELSE (sol.xtndprce-sol.extdcost)/sol.extdcost * 100.00 END ELSE (sol.xtndprce-(pop.unitcost * sol.quantity))/(pop.unitcost * sol.quantity)  * 100.00 END) as 'AvgMargin' from sop10200 sol LEFT OUTER JOIN SOP60100 sop on sol.sopnumbe = sop.sopnumbe and sol.lnitmseq = sop.lnitmseq LEFT OUTER JOIN POP10110 pop on sop.ponumber = pop.ponumber and sop.ord = pop.ord WHERE SOL.SOPNUMBE = '" + sopEntryWindow.SopNumber.Value + "'"; 
                GPDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                GPDataAdapter.SelectCommand = GPCommand;
                GPDataAdapter.TableMappings.Add("Table", "OrderSummary");


                this.txtTotalQuantity.DataBindings.Add("Text", GPDataSet.Tables["OrderSummary"], "TotalQTY").ToString();
                this.txtTotalQuantity.Text = Convert.ToString("N0");
                this.txtTotalPrice.DataBindings.Add("Text", GPDataSet.Tables["OrderSummary"], "TotalPrice").ToString();
                this.txtTotalPrice.Text = Convert.ToString("N2");
                this.txtTotalCost.DataBindings.Add("Text", GPDataSet.Tables["OrderSummary"], "TotalCost").ToString();
                this.txtTotalCost.Text = Convert.ToString("N2");
                this.txtAvgMargin.DataBindings.Add("Text", GPDataSet.Tables["OrderSummary"], "AvgMargin").ToString();
                this.txtAvgMargin.Text = Convert.ToString("N2");

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The Textbox control does not allow a format mask, you can use key and change events to keep formatting it, but easier to just use MaskedTextBox.
rwheeler23Author Commented:
Yes, but using the MaskedTextBox in the Mask box if I want to have a currency field that can be up to 7 digits to the left of decimal and 2 digits to the right and I do NOT want to see the underline character plus have the dollar sign to the left, what mask do I type?

I tried $99,999,999.99, $00,000,000.00, and $##,###,###.## but it keep putting the underline character. I jsut want to be $1,234,567.89 or $29.99.
Set the .Mask property to ">LCCC 9LL"
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Ignore that, I just tried it and I see your point about the ___ which is what you are trying to get rid of.  Check out this link for a very short bit of code that handles free-form input and always-formatted display on exit.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwheeler23Author Commented:
This code has this command in it. What context must I include to get it to recognize Globalization?
If Not Decimal.TryParse(Me.TextBox1.Text, _
                            Globalization.NumberStyles.Currency, _
                            Nothing, _
rwheeler23Author Commented:
I tried using this but it does not recognize NumberStyles and of course Currency
This is VS 2008 C#
using System.Globalization.NumberStyles.Currency
rwheeler23Author Commented:
I have typing in the entire context and it does not like this line:

 if (!decimal.TryParse(this.txtTotalPrice.Text, System.Globalization.NumberStyles.Currency , null, currency))
It jsut does understand this line.
private void txtTotalPrice_Validating(object sender, CancelEventArgs e)
            decimal currency = default(decimal);
            //Convert the current value to currency, with or without a currency symbol.
            if (!decimal.TryParse(this.txtTotalPrice.Text, System.Globalization.NumberStyles.Currency.ToString , null, currency))
            /*Don't let the user leave the field if the value is invalid. */
                this.txtTotalPrice.HideSelection = false;
                MessageBox.Show("Please enter a valid currency amount.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);

                this.txtTotalPrice.HideSelection = true;
            e.Cancel = true;

Open in new window

rwheeler23Author Commented:
Is there some reference I need to add to my project? If so, which one?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.