Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
.NET 4 and Visual Studio 2010 General Discussions For discussing anything about .NET 4, WPF, WCF, the rest of the .NET 4 Framework, and Visual Studio 2010 that isn't about a specific Wrox book. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET 4 and Visual Studio 2010 General Discussions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 4th, 2012, 07:57 AM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to compute the total in datagridview vb 2010?

Hye, i am using vb 2010. i need help in order to do a program that can calculate the total of all the values in the specific column in the datagridview, something like in the link below. Thanks

http://i.stack.imgur.com/Nzoeu.jpg
  #2 (permalink)  
Old November 4th, 2012, 08:10 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

You can do this will the following code:-

Code:
Dim totalValue As Integer
For Each dgvRow As DataGridViewRow In DataGridView1.Rows
  If Not dgvRow.IsNewRow Then
    totalValue += CInt(dgvRow.Cells(1).Value)
  End If
Next
MsgBox(totalValue)
Hope that helps.

Cheers,

Ian
The Following User Says Thank You to Ian Ryder For This Useful Post:
adrian87 (May 9th, 2013)
  #3 (permalink)  
Old November 4th, 2012, 09:07 AM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it works!
thank you very much
  #4 (permalink)  
Old November 4th, 2012, 10:04 AM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

one more question

can i set one of the column to be visible = false by programming?

ive tried dgvRow.Cells(1).Visible =false but error occurred
  #5 (permalink)  
Old November 4th, 2012, 10:14 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

Yes you can but you do not do it by trying to set an individual cell's visibility to false. You do it by using:-

DataGridView1.Columns(1).Visible = False

Hope that helps.

Cheers,

Ian
  #6 (permalink)  
Old November 5th, 2012, 05:32 AM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you so much, you've helped a lot ^__^

Btw, can i set the delete button to delete selected rows or cells only?
i used BindingNavigatorDeleteItem.PerformClick() but that will delete all rows
  #7 (permalink)  
Old November 5th, 2012, 05:52 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

You can clear cells but you cannot physically delete cells. If you want to delete a row however then you can do this:-

Code:
If DataGridView1.SelectedRows.Count > 0 Then
  For Each dgvRow As DataGridViewRow In DataGridView1.SelectedRows
    DataGridView1.Rows.Remove(dgvRow)
  Next
Else
  MsgBox("Nothing To Delete!")
End If
Hope that helps.

Cheers,

Ian
The Following User Says Thank You to Ian Ryder For This Useful Post:
adrian87 (May 9th, 2013)
  #8 (permalink)  
Old November 5th, 2012, 11:33 PM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks

but i have another problem
i cannot insert decimal points into the cell in dtagridview...
when i run the program, then i insert for example 2.3 into the datagridview, an error will pop up..like in the link below
https://fbcdn-sphotos-c-a.akamaihd.n...44840074_n.jpg

how can i fix this?
  #9 (permalink)  
Old November 6th, 2012, 12:40 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

The answer to your question is the first word on the second line of the error statement that you have posted. You need to look at how you have created your DataGridView columns to allow decimal values. If you create the column as DataGridViewTextBoxColumn you will have no problem with decimal values.

Hope that helps.

Cheers,

Ian
  #10 (permalink)  
Old November 13th, 2012, 07:01 PM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hye there :)

i juz want to know how can i save the data inside the datagridview?




Similar Threads
Thread Thread Starter Forum Replies Last Post
New to VB 2010 - I need help with OLEDB toconce Visual Basic 2010 General Discussion 10 May 25th, 2015 03:10 AM
Moving up from VB5 to VB 2010 VB2010Newbie Visual Basic 2010 General Discussion 5 June 17th, 2011 09:33 AM
Trouble getting form to appear - VB 2010 jericho Visual Basic 2010 General Discussion 1 June 6th, 2011 06:50 AM
Beginning Microsoft VB 2010 Tony1997 .NET 4 and Visual Studio 2010 General Discussions 2 April 3rd, 2011 11:19 AM
Sum of numbers that was insert will automatic compute and appear in total text field newphpcoder PHP Databases 0 December 23rd, 2010 02:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.