We help IT Professionals succeed at work.

price column in datagridview

ANAT2403
ANAT2403 asked
on
862 Views
Last Modified: 2013-11-07
In WInforms VS2005 with C# I have a datagridview and I want to show a column with price.
How do I set this column?
Anat
Comment
Watch Question

Is this column called Price available in the Database or you just want a column with price?

>> Pseudo Code to create a dummy datatable and making the datagrid to display a Price Column
DataTable dtTable = new DataTable();
dtTable.Columns.Add("Price");
dr1 = dtTable.Rows.NewRow();
dr2 = dtTable.Rows.NewRow();
dr3 = dtTable.Rows.NewRow();

dr1[0] = 1;
dr1[0] = 2;
dr1[0] = 3;

dataaGridView1.DataSource = dtTable;

Author

Commented:
this column already exist in my datatable and is declared as a decimal type. In the database it is declared as money. the question is what typw to give this field in the datagridview so that the currency will show?
Anat
Top Expert 2007

Commented:
When you add the column to the DataGridView, what are you currently using for:
newColumn.ValueType = ?

Jim

Author

Commented:
This is the way I declare this column:
            dgvColText = new DataGridViewTextBoxColumn();
            dgvColText.Name = "Price";
            dgvColText.DataPropertyName = "Price";
            pdGVInventory.Columns.Add(dgvColText);
Do I have to declare it differently? and what properties do I have to add so that I will control the digits
after the decimal points and the currency symbol?
Thankyou
Anat
Top Expert 2007

Commented:
Anat - Do the rows contain different kinds of currency in this column, or are all the same? If different, how do you know which row contains which type? If the same, it is probably easiest to add the currency symbol to the column header.

When you say it is "money" in the DB, can I infer from that you are using SQL Server?

Jim
Top Expert 2007

Commented:
Sorry - one more question: Are you doing any arithmetic with the values from this column in the DataTable?

Jim
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Top Expert 2007

Commented:
Glad you found it. Good luck.

Jim

Author

Commented:
By the way if I want to show a specific currency do I have to change the culture or is there
another way?
Thankyou
Anat
CERTIFIED EXPERT

Commented:
Closed, 500 points refunded.
modus_operandi
Community Support Moderator
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.