472,784 Members | 941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 5866
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 ...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?

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.