Hi Guys,

Hope you can help. (Bit of a N00b still).. I've written an Functioning Program (Good start!)

However, I was wondering if there is a way for the data that is being shown currently in the Grid view to be shown with 'Decimal Places? The Data is Being pulled in via ODBC from a Access DB. The Table Column has been setup as 'DataType' = Currency with Decimal Places Defaulted to '1'.

When looking at the data in the DB the Decimal Places are in the correct place but when pulling the data via ODBC into the GridView it does not show.

Currently code looks something like this:

//Tells the dataGridView to load with the information stored in table called 'cashCustomers' in the DataSet (DS)//
                dataGridView2.DataSource = ds3.Tables["OrdersCashCustomers"];

                //Change the Headers on the DataGridView2//
                dataGridView2.Columns["cashQTY"].HeaderText = "QTY";
                dataGridView2.Columns["cashDescription"].HeaderText = "DESCRIPTION";
                dataGridView2.Columns["cashSupplier"].HeaderText = "SUPPLIER";
                dataGridView2.Columns["cashDate"].HeaderText = "DATE";
                dataGridView2.Columns["cashCost"].HeaderText = "COST";
                dataGridView2.Columns["cashSell"].HeaderText = "SELL";

                //Hide Columns on DataGridView2//
                dataGridView2.Columns["cashID"].Visible = false;
                dataGridView2.Columns["CashAccountRef_FKID"].Visible = false;

            }

            else if (radioButton2.Checked == true)
            {
                //Looks at the row Selected in the GridView and then takes the Account Number and Stores in a String Value called 'Customer ID'//
                DataGridViewRow drow = dataGridView1.SelectedRows[0];
                String CustomerID = Convert.ToString(drow.Cells[0].Value);

                //Pulls Across the Account number so the Orders for Accounts can be joined//
                txtAccRef.Text = dataGridView1.SelectedCells[0].Value.ToString();
                txtAccName.Text = dataGridView1.SelectedCells[1].Value.ToString();
                txtAccAddr1.Text = dataGridView1.SelectedCells[3].Value.ToString();
                txtAccAddr2.Text = dataGridView1.SelectedCells[4].Value.ToString();
                txtAccTown.Text = dataGridView1.SelectedCells[2].Value.ToString();
                txtAccCounty.Text = dataGridView1.SelectedCells[5].Value.ToString();
                txtAccPostCode.Text = dataGridView1.SelectedCells[6].Value.ToString();

I'm Sure I need to 'Convert.ToInt32' or something like that.. But I'm not really to sure where to do this.

It is 'SelectedCells[5]' and 'SelectedCells[6]' which hold the 'Cost' and 'Value' figures.

Look forward to any help being offered.

Regards
Mark

You can give the ToString method of the Decimal type a format-string.
Read this article.

Thanks ddanbe, for your response.

Are you able to provide me with an example how it would be used in the above code?

Regards
Mar

This could be done with:
dataGridView2.Rows[i].Cells[j].Value = MyDecimal.ToString("0.00");
Here is some more info about string formats.

Looks like I'm getting this error when attempting to Convert?

I thought you wanted to set the Value in the DGV
For the textbox do:
txtSell.Text = dataGridView1.SelectedCells[6].Value.ToString("0.00");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.