Calculating Cells Value in DataGridView Using VB.Net
Submitted by janobe on Wednesday, September 19, 2018 - 17:06.
In this tutorial, I will teach you how to calculate the cells value in the datagridview using vb.net. This method will help you how to assign grades and points in the specific cells when entering the score in another cell. See the step by step below for your guide.
The complete sourcecode is included. You can download it and run it on your computer.
For more question about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
FB Account – https://www.facebook.com/onnaj.soicalap
Or feel free to comment below.
Creating Applicaion
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application. After that, do the form just like shown below.
Step 2
Double click the form and do the following code for adding data in the datagridview.- With DataGridView1
- .Rows.Add("Math")
- .Rows.Add("English")
- .Rows.Add("Science")
- End With
Step 3
Go back to the design views and click the datagridview. In the properties, click events just like the lightning bolt and double clickcellendedit
event handler.

Step 4
Do the following code inside the method for calculating the score, grades and points.- Try
- Dim colIndex As Integer = e.ColumnIndex
- If colIndex = 1 Then
- Dim DataGridView1cell As Integer = DataGridView1.CurrentRow.Cells(1).FormattedValue
- Select Case DataGridView1cell
- Case 0 To 24
- DataGridView1.CurrentRow.Cells(2).Value = "E"
- DataGridView1.CurrentRow.Cells(3).Value = "1"
- Case 25 To 29
- DataGridView1.CurrentRow.Cells(2).Value = "D-"
- DataGridView1.CurrentRow.Cells(3).Value = "2"
- Case 30 To 34
- DataGridView1.CurrentRow.Cells(2).Value = "D"
- DataGridView1.CurrentRow.Cells(3).Value = "3"
- Case 35 To 39
- DataGridView1.CurrentRow.Cells(2).Value = "D+"
- DataGridView1.CurrentRow.Cells(3).Value = "4"
- Case 40 To 44
- DataGridView1.CurrentRow.Cells(2).Value = "C-"
- DataGridView1.CurrentRow.Cells(3).Value = "5"
- Case 45 To 54
- DataGridView1.CurrentRow.Cells(2).Value = "C"
- DataGridView1.CurrentRow.Cells(3).Value = "6"
- Case 55 To 59
- DataGridView1.CurrentRow.Cells(2).Value = "C+"
- DataGridView1.CurrentRow.Cells(3).Value = "7"
- Case 60 To 64
- DataGridView1.CurrentRow.Cells(2).Value = "B-"
- DataGridView1.CurrentRow.Cells(3).Value = "8"
- Case 65 To 69
- DataGridView1.CurrentRow.Cells(2).Value = "B"
- DataGridView1.CurrentRow.Cells(3).Value = "9"
- Case 70 To 74
- DataGridView1.CurrentRow.Cells(2).Value = "B+"
- DataGridView1.CurrentRow.Cells(3).Value = "10"
- Case 75 To 79
- DataGridView1.CurrentRow.Cells(2).Value = "A-"
- DataGridView1.CurrentRow.Cells(3).Value = "11"
- Case 80 To 100
- DataGridView1.CurrentRow.Cells(2).Value = "A"
- DataGridView1.CurrentRow.Cells(3).Value = "12"
- Case Else
- DataGridView1.CurrentRow.Cells(2).Value = "0"
- DataGridView1.CurrentRow.Cells(3).Value = "0"
- End Select
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
Add new comment
- 1043 views