Visual Basic - ayuda, suma de columnas

Life is soft - evento anual de software empresarial
   
Vista:

ayuda, suma de columnas

Publicado por cristian (1 intervención) el 15/12/2014 22:20:12
hol, es que quiero sumar las columnas y flas mpares de un dagridview, las filas ya las pude sumar pero las columnas no e podido sumarlas, este es el codigo que llevo...

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
96
97
98
99
100
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim i, j As Integer
        Dim tabla(5, 5) As String
 
        With DataGridView1
 
            .Columns.Add("", "")
            .Columns.Add("", "")
            .Columns.Add("", "")
            .Columns.Add("", "")
            .Columns.Add("", "")
 
            .RowCount = 5
 
            For i = 0 To 4
 
                For j = 0 To 4
 
                    tabla(i, j) = InputBox("Digite un número")
                    .Item(i, j).Value = tabla(i, j)
 
                Next
 
            Next
 
 
 
        End With
 
 
 
        Dim fila1 As Integer = 0
        Dim fila3 As Integer = 2
        Dim fila5 As Integer = 4
 
        Dim sumFila1 As Integer = (From cell As DataGridViewCell In DataGridView1.Rows.Item(fila1).Cells Select CInt(cell.Value)).Sum
 
        Dim sumFila3 As Integer = (From cell As DataGridViewCell In DataGridView1.Rows.Item(fila3).Cells Select CInt(cell.Value)).Sum
 
        Dim sumFila5 As Integer = (From cell As DataGridViewCell In DataGridView1.Rows.Item(fila5).Cells Select CInt(cell.Value)).Sum
 
        Label1.Visible = True
        Label1.Text = "La suma de los valores de la primer fila es de " & sumFila1
 
        Label2.Visible = True
        Label2.Text = "La suma de los valores de la tercera fila es de " & sumFila3
 
        Label3.Visible = True
        Label3.Text = "La suma de los valores de la quinta fila es de " & sumFila5
 
 
 
        Dim Total As Single
        Dim Col1 As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
        For Each row As DataGridViewRow In Me.DataGridView1.Rows
            Total += Val(row.Cells(Col1).Value)
        Next
        Me.Label4.Text = "la suma de los valores de la primera columnas es de " & Total.ToString
        Dim Total1 As Single
        Dim Col3 As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
        For Each row As DataGridViewRow In Me.DataGridView1.Rows
            Total1 += Val(row.Cells(Col3).Value)
        Next
        Me.Label5.Text = Total.ToString
        Dim Total2 As Single
        Dim Col5 As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
        For Each row As DataGridViewRow In Me.DataGridView1.Rows
            Total2 += Val(row.Cells(Col5).Value)
        Next
        Me.Label6.Text = Total.ToString
 
 
    End Sub
 
    Private Sub VOLVERALMENUINICIALToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VOLVERALMENUINICIALToolStripMenuItem.Click
        Me.Close()
        mnprincipal.Show()
    End Sub
 
    Private Sub SALIRToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SALIRToolStripMenuItem.Click
        MsgBox("desea abandonar el programa", 36)
        MsgBox("esta seguro de salir", 36)
        MsgBox("hasta pronto")
        End
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DataGridView1.Columns.Clear()
        DataGridView1.Rows.Clear()
        Label1.Text = ""
        Label2.Text = ""
        Label3.Text = ""
        Label4.Text = ""
        Label5.Text = ""
        Label6.Text = ""
 
 
 
    End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder