VS C# 2008 Formats

I have been trying serveral formats and I have two issues I cannot resolve.
One is on the text fields Part Number, Part Description and Vendor ID. If you look at the right side of the fields it puts 3 periods. Is there anyway, besides making the columns overly wide to prevent this? Secondly, the column for QTY I am trying to get to display with zero decimal places. The field in SQL is defined as decimal(19,5). Is there any way with just a format parameter to have it display with no decial places? This fields are sitting on a datagridview control.
dgvOrderDetail.ReadOnly = true;
            dgvOrderDetail.RowHeadersVisible = false;
            dgvOrderDetail.DataSource = GPDataSet.Tables["OrderDetail"].DefaultView;
            dgvOrderDetail.Columns[0].Width = 110;
            dgvOrderDetail.Columns[0].HeaderText = "Part Number";

            dgvOrderDetail.Columns[1].Width = 200;
            dgvOrderDetail.Columns[1].HeaderText = "Part Description";

            dgvOrderDetail.Columns[2].Width = 60;
            dgvOrderDetail.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvOrderDetail.Columns[3].DefaultCellStyle.Format = "{0:0.#}"; 
            dgvOrderDetail.Columns[2].HeaderText = "QTY";

            dgvOrderDetail.Columns[3].Width = 60;
            dgvOrderDetail.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvOrderDetail.Columns[3].DefaultCellStyle.Format = "c";
            dgvOrderDetail.Columns[3].HeaderText = "Unit Price";

            dgvOrderDetail.Columns[4].Width = 60;
            dgvOrderDetail.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvOrderDetail.Columns[4].DefaultCellStyle.Format = "c";
            dgvOrderDetail.Columns[4].HeaderText = "Extended Price";

            dgvOrderDetail.Columns[5].Width = 70;
            dgvOrderDetail.Columns[5].HeaderText = "PO Number";

            dgvOrderDetail.Columns[6].Width = 60;
            dgvOrderDetail.Columns[6].HeaderText = "Vendor ID";

            dgvOrderDetail.Columns[7].Width = 60;
            dgvOrderDetail.Columns[7].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvOrderDetail.Columns[7].DefaultCellStyle.Format = "c";
            dgvOrderDetail.Columns[7].HeaderText = "Unit Cost";

            dgvOrderDetail.Columns[8].Width = 60;
            dgvOrderDetail.Columns[8].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvOrderDetail.Columns[8].DefaultCellStyle.Format = "c";
            dgvOrderDetail.Columns[8].HeaderText = "Extended Cost";

            dgvOrderDetail.Columns[9].Width = 60;
            dgvOrderDetail.Columns[9].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvOrderDetail.Columns[9].DefaultCellStyle.Format = "p2";
            dgvOrderDetail.Columns[9].HeaderText = "Profit Margin";

Open in new window

VS-Formats.bmp
LVL 1
rwheeler23Asked:
Who is Participating?
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.

 
SriVaddadiCommented:
0
 
käµfm³d 👽Commented:
In line 12 of your post, you are setting the format string for the cell, but you are setting it on column 3, not 2. Also, to change it to rounding, use the format string "{0:0}".
// Change line 12 from

dgvOrderDetail.Columns[3].DefaultCellStyle.Format = "{0:0.#}"; 

// To

dgvOrderDetail.Columns[2].DefaultCellStyle.Format = "{0:0}"; 

Open in new window

0

Experts Exchange Solution brought to you by ConnectWise

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
 
SriVaddadiCommented:
dgvOrderDetail.Columns[3].DefaultCellStyle.Format = "{G0}";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.