Link to home
Start Free TrialLog in
Avatar of ANAT2403
ANAT2403Flag for Israel

asked on

price column in datagridview

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
Avatar of surajguptha
surajguptha
Flag of United States of America image

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;
Avatar of ANAT2403

ASKER

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
When you add the column to the DataGridView, what are you currently using for:
newColumn.ValueType = ?

Jim
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
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
Sorry - one more question: Are you doing any arithmetic with the values from this column in the DataTable?

Jim
ASKER CERTIFIED SOLUTION
Avatar of ANAT2403
ANAT2403
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad you found it. Good luck.

Jim
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
Avatar of modus_operandi
modus_operandi

Closed, 500 points refunded.
modus_operandi
Community Support Moderator