Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 4 and Visual Studio 2010 > .NET 4 and Visual Studio 2010 General Discussions
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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?
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:08 PM.


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