473,385 Members | 1,642 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.

How to calculate cell data in DataGridView VB Express?

11
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 5897
romes
8
Hi there, i am struggling with the same issue. Have you been able to sort it out?
Nov 28 '11 #2
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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

A = Double.Parse(DataGridView1.Item(0, 0).Value)
B = Double.Parse(DataGridView1.Item(1, 0).Value)
C = Double.Parse(DataGridView1.Item(2, 0).Value)
D = Double.Parse(DataGridView1.Item(3, 0).Value)

Z = A + B + C + D

DataGridView1.Item(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
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
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
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
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...
7
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...
2
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...
2
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...
3
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
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...
0
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
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...
2
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 ...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.