[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

DataGrid Totals

Asked by Skwerlz in Microsoft Visual Basic.Net

Tags: datagrid, vb, add, multiply

I have asked about this already. I thought I got what I needed.
Close, but I didn't check the calculations.
Here is what I have, and a picture of what I need.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
Public Class DataGridViewExampleForm
 
    Private Sub DataGridViewExampleForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim font As New Font("Tahoma", 10)
        Dim bold As New Font("Tahoma", 10, FontStyle.Bold)
 
        Me.MeasurementGrid.AutoGenerateColumns = False
        Me.MeasurementGrid.AllowUserToAddRows = False
        Me.MeasurementGrid.AllowUserToDeleteRows = False
        Me.MeasurementGrid.AllowUserToOrderColumns = False
        Me.MeasurementGrid.AllowUserToResizeColumns = False
        Me.MeasurementGrid.AllowUserToResizeRows = False
 
        Me.MeasurementGrid.RowTemplate.Height = 60
        Me.MeasurementGrid.RowHeadersVisible = False
 
        Me.MeasurementGrid.EditMode = DataGridViewEditMode.EditOnEnter
 
        Me.MeasurementGrid.Columns.Clear()
 
        Me.MeasurementGrid.Columns.Add("RowHeader", "")
        Me.MeasurementGrid.Columns.Add("Measurement1", "Measurement 1")
        Me.MeasurementGrid.Columns.Add("Measurement2", "Measurement 2")
        Me.MeasurementGrid.Columns.Add("Total", "Total")
 
        Me.MeasurementGrid.Font = font
 
        Me.MeasurementGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        Me.MeasurementGrid.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False
        Me.MeasurementGrid.ColumnHeadersDefaultCellStyle.Font = bold
 
        Me.MeasurementGrid.RowCount = 4
 
        Me.MeasurementGrid.Columns("RowHeader").ReadOnly = True
        Me.MeasurementGrid.Columns("RowHeader").DefaultCellStyle.BackColor = SystemColors.Control
        Me.MeasurementGrid.Columns("RowHeader").DefaultCellStyle.Font = bold
        Me.MeasurementGrid.Columns("RowHeader").FillWeight = 40
 
        Me.MeasurementGrid.Columns("Total").ReadOnly = True
 
        Me.MeasurementGrid.Height = Me.MeasurementGrid.ColumnHeadersHeight + Me.MeasurementGrid.RowTemplate.Height * Me.MeasurementGrid.RowCount + 3
 
        Me.MeasurementGrid(0, Me.MeasurementGrid.RowCount - 1).Value = "Total:"
 
        For index As Integer = 0 To Me.MeasurementGrid.RowCount - 2
            Me.MeasurementGrid(0, index).Value = (index + 1) & "."
        Next
 
        For Each column As DataGridViewTextBoxColumn In Me.MeasurementGrid.Columns
            column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        Next column
 
        Me.MeasurementGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
 
    End Sub
 
    Private Sub MeasurementGrid_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MeasurementGrid.CellEndEdit
        Dim columnSum(1) As Double
        If Not Me.MeasurementGrid.Columns(e.ColumnIndex).ReadOnly Then
            Dim sum As Double = 0
            For Each row As DataGridViewRow In Me.MeasurementGrid.Rows
                Dim m1 As Double = IIf(row.Cells("Measurement1").Value IsNot Nothing, Val(row.Cells("Measurement1").Value), Double.MinValue)
                Dim m2 As Double = IIf(row.Cells("Measurement2").Value IsNot Nothing, Val(row.Cells("Measurement2").Value), Double.MinValue)
 
                If m1 <> Double.MinValue AndAlso m2 <> Double.MinValue Then
 
                    columnSum(0) += m1
                    columnSum(1) += m2
 
                    Dim total As Double = m1 * m2
 
                    row.Cells("Total").Value = total
                    sum += total
                End If
            Next row
 
            If sum <> 0 Then
                Me.MeasurementGrid("Measurement1", Me.MeasurementGrid.RowCount - 1).Value = columnSum(0)
                Me.MeasurementGrid("Measurement2", Me.MeasurementGrid.RowCount - 1).Value = columnSum(1)
                Me.MeasurementGrid("Total", Me.MeasurementGrid.RowCount - 1).Value = sum
            End If
        End If
    End Sub
 
End Class
 
Open in New Window Select All 
 
    
 
 Please take a moment to respond  
    Did this comment work for you?  Yes  Partially  No Was the comment complete?  Yes  Partially  No Was the comment easy to understand?  Yes  Partially  No Overall, how would you rate this comment?  Excellent  Good  Average  Submit  |  Cancel   
   
 01.09.2009 at 11:47AM PST, ID: 23339521
Attachments:
 
What I need this code to do
What I need this code to do
 
 
Related Solutions
 
Loading Advertisement...
 
[+][-]01/09/09 04:44 PM, ID: 23341749Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/10/09 03:49 AM, ID: 23343266Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/10/09 03:55 AM, ID: 23343282Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/10/09 11:00 AM, ID: 23344810Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/11/09 05:21 AM, ID: 23348149Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Microsoft Visual Basic.Net
Tags: datagrid, vb, add, multiply
Sign Up Now!
Solution Provided By: vbturbo
Participating Experts: 1
Solution Grade: A
 
[+][-]06/10/09 08:13 AM, ID: 24592564Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625