Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

price column in datagridview

Posted on 2007-10-07
11
Medium Priority
?
828 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
0
Comment
Question by:ANAT2403
10 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20029991
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;
0
 

Author Comment

by:ANAT2403
ID: 20030091
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
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20031164
When you add the column to the DataGridView, what are you currently using for:
newColumn.ValueType = ?

Jim
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ANAT2403
ID: 20031197
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
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20031236
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
0
 
LVL 22

Expert Comment

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

Jim
0
 

Accepted Solution

by:
ANAT2403 earned 0 total points
ID: 20031256
Hi,
I found the solution: This is what I have to add to have a currency with no digits after the decimal point:
           DataGridViewCellStyle columnpricestyle = new DataGridViewCellStyle();
            columnpricestyle.Format = "C0";
            pdGVInventory.Columns.Add(dgvColText);
            pdGVInventory.Columns["Price"].DefaultCellStyle = columnpricestyle;
Thankyou anyhow for trying to help.
Anat
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20031354
Glad you found it. Good luck.

Jim
0
 

Author Comment

by:ANAT2403
ID: 20032739
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
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20077297
Closed, 500 points refunded.
modus_operandi
Community Support Moderator
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question