473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

calculated column in datagridview

2
Hi friends
I am new to vb.net , I am having difficulty to add a calculated column to calculate
amount = salesPrice*qty in the code below
please help me

Expand|Select|Wrap|Line Numbers
  1.  
  2.  DataGridView1.ColumnCount = 5
  3.         DataGridView1.Columns(0).Name = "Product ID"
  4.         DataGridView1.Columns(1).Name = "Product Name"
  5.         DataGridView1.Columns(2).Name = "salesPrice"
  6.         DataGridView1.Columns(3).Name = "qty"
  7.         DataGridView1.Columns(4).Name = "amount"
  8.  
  9.         Dim row As String() = New String() {"1", "Product 1"}
  10.         DataGridView1.Rows.Add(row)
  11.         row = New String() {"2", "Product 2"}
  12.         DataGridView1.Rows.Add(row)
  13.         row = New String() {"3", "Product 3"}
  14.         DataGridView1.Rows.Add(row)
  15.         row = New String() {"4", "Product 4"}
  16.         DataGridView1.Rows.Add(row)
  17.  
Oct 29 '12 #1
4 5962
Frinavale
9,735 Expert Mod 8TB
See if the DataGridView CellParsing Event can help you achieve what you are looking for.

-Frinny
Oct 29 '12 #2
rony08
2
Hi
Thanks for your reply, I have figured out on adding expression column another way but now having difficulty to get the correct out put . any bit of info would be helpful
Expand|Select|Wrap|Line Numbers
  1.         Dim dt As New DataTable
  2.         dt.Columns.Add("col1")
  3.         dt.Columns.Add("col2")
  4.         dt.Columns.Add("col3")
  5.         dt.Columns.Add("col4")
  6.         dt.Columns.Add("total")
  7.         dt.Columns("total").Expression = "[col1]*[col2]"
Nov 1 '12 #3
In the cell leave event of Quantity column multiply the column of item amount and Quantity and set the cell value of total Amount column. And it is nice if you give Save button to save the records.
Nov 2 '12 #4
Frinavale
9,735 Expert Mod 8TB
@roy08
That is really cool!
I have never used the DataColumn.Expression Property for anything except filtering. I didn't even realize you could do that.

Anyways, according to the documentation (in the link I just posted) it seems you do not have to have the [] around the column names.

Try removing them and see if it fixes your problem :)

I love it when I learn something new :)

-Frinny
Nov 2 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hari | last post by:
I have got a calculated column but i want to insert this column in the third column of the datagrid. How can i do that in C# C#? Thank you
3
by: Kurt Schroeder | last post by:
can you populate a colmun in a data grid with a calculated value and can this be done on databind? I have a datagrid that is populated with a shopping cart. This data comes from the database. I...
8
by: Dan Keeley | last post by:
Hi, I have a dataset which is used to populate my datagrid something like this: My question is, how do I add a caluclated display column to the datagrid? It will be based on ScoreCardScore... ...
0
by: Manish | last post by:
Hey Guys I am using a datagrid to extract information out of SQL Server datbase. The fields extracted are category,week,budget,Last Year,Forecast and Projection. Also i add a calculated column...
0
by: astro | last post by:
I have a non-updatable column in a SQL:-Server view that represents a 1-to {0,1} relation with a child table. I want the end-user to be able to change this value. This view is generated with...
0
by: samir | last post by:
hi i have a datagrid where i display some columns. i want to have some columns from the db and 2 i calculate,i can display it but problem is how to sort the calculated columns. here is what i am...
0
by: ksjayhawk | last post by:
This isn't very important to me, but my brain is arguing that there is an elegant way of performing the below "cho+protein+fat" calculation -- without repeating the calculations many times (below...
4
by: KA NMC | last post by:
I'm looping thru a datagrid - as it loops I want the application to do calculations and place that result in a column for each record. - Right now it is only doing the calculation for the first...
19
mshmyob
by: mshmyob | last post by:
Going to post this real fast since I have to go out, so I hope I get all the pertenent info in the message. I have a subform and the results are based on a select query. Results are say like so...
5
by: drews1f | last post by:
Hello, I have been trying for days to add more than one database column into a cell but im not having any luck. Here is my code: Dim mortAdapter As New SqlDataAdapter("(SELECT...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.