473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to calculate cell data in DataGridView VB Express?

11 New Member
Hello,

I would like to calculate cells in DataGridView ( VB Express)

My datagridview1 looks something like this.
--------------------------------------…
Row# col1 col2 col3 Col 4
--------------------------------------…
Row1 25 13 2
Row2 26 24 4
Row3 17 13 10
Row4 etc etc etc
Row5
etc

Now I want to be able to calculate each cells when I press button1 the datagridview1 should calculate automaticly.
the result will be in col 4
For example: Then the datagridview1 would look like this.


Row# col1 col2 col3 Col 4
--------------------------------------…
Row1 25 13 2 24 (25-13*2)
Row2 26 24 4 8 (26-24*8)
Row3 17 13 10 40 (17-13*10)
Row4 etc etc etc etc
Row5
etc
Pls, any ideas and codes would be very helpful.
" Notes"
I am very new to VB Express.
The table have fixed data
I have more than 1000 rows to be calculate
I am not using SQL

Thank you in advance
Feb 6 '11 #1
5 5906
romes
8 New Member
Hi there, i am struggling with the same issue. Have you been able to sort it out?
Nov 28 '11 #2
Mike Newman
5 New Member
Hi,

I have just seen your request for help. I hope you still log in to see if you have had a response.

You have not said if your datagridview is data bound or not. As you are still learning, I have assumed that it is not data bound.

One thing to remember is that the datagridview rows and columns are zero based when naming them so they do not start at "1" but "0".

Here is my offering for calculating a single row. You can expand on this to meet your needs.

Public Class Form1

Dim A As Double
Dim B As Double
Dim C As Double
Dim D As Double
Dim Z As Double

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

A = Double.Parse(Da taGridView1.Ite m(0, 0).Value)
B = Double.Parse(Da taGridView1.Ite m(1, 0).Value)
C = Double.Parse(Da taGridView1.Ite m(2, 0).Value)
D = Double.Parse(Da taGridView1.Ite m(3, 0).Value)

Z = A + B + C + D

DataGridView1.I tem(4, 0).Value = Z.ToString

End Sub
End Class

Please get back to me if you need more help.

Mike Newman
Jan 9 '12 #3
Mike Newman
5 New Member
Hi Again,

My previous post allows you to enter the required numbers into the datagridview at run time and click on a button "Button1" to do the calculations.


Mike
Jan 9 '12 #4
romes
8 New Member
Hi Mike
Many thanks for your mail. My datagrid is attached to a database. It has been a while since i looked at my program which is working, i think i ended up doing pages of code to do the same thing as i wanted to do with the datagridview. I have a very unique and complicated piece of software, it took my a year and a half to master. Whilst creating it i was studying MCPD (for a absolute greenie it was incredibly hard). But as i went on i implimented what i learnt and in june last year i finished my studies and then another 6 months and i was done. Bit of a overshare hey? hehe. So, would there be a way to do calculations with the datagridview if it is attached to a db?

Kind regards Rome'



@Mike Newman
Jan 11 '12 #5
Mike Newman
5 New Member
Hi Rome'

As I do not know how you have constructed your database, may I suggest you look at the set of turorials made by Beth Massi of Microsoft. The entire set are available for download here: http://archive.msdn.microsoft.com/vb...x?ReleaseId=16

In these videos she shows you how to create databases and datagrdviews directly from a datasets but not how to perform calculations. When you are familiar with those procedures you can apply my code to the columns that you have created in your database.

Have a look at those and get back to me if you need more help.

Mike
Jan 11 '12 #6

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

Similar topics

1
4884
by: Niche | last post by:
I am new to VB.net, I know how to make command buttons and text boxes on a VB form. I need help with writing the code to ope and Excel 97 spreadsheet and place a cell data (A1) into my VB.net textbox. How do I code to open a Excel file and then read a cell's contents??
7
1860
by: JohnSmith90 | last post by:
I want to highlight the entire cell data for all rows of a particular column in a data grid. I do not want to fill the back ground color of the cell. How to do that in a data grid? <span style='background-color: #FFFF04'>highlighted Text</span>
2
1256
by: Bsr | last post by:
Hi, Please tell the solutions for the following queries. 1. How to read the data from Excel file. 2. How to get the cell data in to the varaible from existed Excel file. Its very argent for me. Please do the needful
2
2109
by: mvenkatesan | last post by:
Hi guys I am developing a project, use datagridview the datas are stored arraylist I am bind the data using datatable & databind the datagridview data displayed perfect. But i am set one column to hidden on datatable for below line data1.columnmapping = mappingtype.hiidden how to retrieve the hidden column value?
3
1829
nirmalsingh
by: nirmalsingh | last post by:
hai all, How to place a control dynamically in cell of datagridview control?in run time. i am using C#.net(Windows application) thanx in advance with Cheers Nirmal
2
3097
by: Claudia Fong | last post by:
Hi I have a datagrid with 12 columns and various rows... what I want to do is to get the value of each cell, e.g. column3 row1, column4 row1, etc.. I was using dataGridView1.Rows.Cells but I got an error of System.Windows.Forms.DataGridView' does not contain a definition for 'RowIndex'
0
2331
by: krishnaneeraja | last post by:
Hi, I am working on windows application. In that i want to place name in bold,address,url in link in one cell using datagridview. please help me.
3
2515
by: KrishnaSarala | last post by:
Hi All IT developer and C# expert please help me urgent. I'm working on a project of Bakery Management. I'hd shown the room booked in hotel in Datagridveiw Control. My client require the cell color in different colors when he enters in particular cell. I had written code in dgv_Formatting Event for coloring but all cells of Datagriveiw are going...
2
1920
by: Ghayas | last post by:
Hello, its quite strange that i m itearing a gridview to get some of its cell data but its not show me data, i m doing like this for i=0 to GView.rows.count-1 str=GView.rows(i).cell(0).text next but i m unable to get cell data any idea?
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.