 |
.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
|
|
|

November 4th, 2012, 07:57 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

November 4th, 2012, 08:10 AM
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
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:
|
|

November 4th, 2012, 09:07 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
it works!
thank you very much 
|

November 4th, 2012, 10:04 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

November 4th, 2012, 10:14 AM
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
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
|

November 5th, 2012, 05:32 AM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

November 5th, 2012, 05:52 AM
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
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:
|
|

November 5th, 2012, 11:33 PM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

November 6th, 2012, 12:40 AM
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
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
|

November 13th, 2012, 07:01 PM
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hye there :)
i juz want to know how can i save the data inside the datagridview?
|
|
 |