|
-
Oct 6th, 2011, 01:56 PM
#1
[RESOLVED] Perform calculation after user input on DataGridView
Hi guys 
I have DataTable, and is bound to DataGridView. So, when the user inputs some values in 4 columns, it would calculate the sum and put it in the last 2nd last column.
Here's the code that I'm experimenting:
vb.net Code:
Private Sub DataGridView1_RowLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowLeave
Dim i As Integer
Dim intTotal As Integer = 0
For i = 5 To DataGridView1.Columns.Count - 3
If Not DataGridView1.Item(e.RowIndex, i).FormattedValue = Nothing Then intTotal += Integer.Parse(DataGridView1.Item(e.RowIndex, i).FormattedValue.ToString)
Next
dt.Rows(e.RowIndex).Item("Total") = intTotal
'DataGridView1.Item(e.RowIndex, DataGridView1.Columns.Count - 2).FormattedValue = intTotal
'MessageBox.Show(e.RowIndex)
End Sub
But when the form is loaded, it would give an error saying out of bounds.
So, basically it should sum up certain columns when the user enters numbers into it and then display it in the last column.
I think, there would be a better way to do this. If you have some suggestions, let me know.
Thanks
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|