You are on page 1of 2

Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.

Load End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick DataGridView1.RowCount = 5 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGridView3.ColumnCount = TextBox1.Text DataGridView3.RowCount = TextBox2.Text Dim rowNumber As Integer = 1 For Each row As DataGridViewRow In DataGridView3.Rows If row.IsNewRow Then Continue For row.HeaderCell.Value = "Proveedor " & rowNumber rowNumber = rowNumber + 1 If rowNumber = TextBox2.Text Then row.HeaderCell.Value = "Demanda " End If Next DataGridView3.AutoResizeRowHeadersWidth( _ DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders) DataGridView3.Columns(0).Name = "Aeropuerto1" DataGridView3.Columns(1).Name = "Aeropuerto2" DataGridView3.Columns(2).Name = "Aeropuerto3" DataGridView3.Columns(3).Name = "Oferta" End Sub Private Sub DataGridView3_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellContentClick End Sub Private Columna As Integer = 3 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Total As Integer = 0 'Acumular el total Dim UltimaFila As Integer = Me.DataGridView3.Rows.Count 'Solo calculamos si modificamos la columna definida If Me.DataGridView3.CurrentCell.ColumnIndex = Columna Then For Each row As DataGridViewRow In Me.DataGridView3.Rows If row.Index < UltimaFila - 1 Then Total += row.Cells(Columna).Value Next Me.DataGridView3.Rows(UltimaFila - 1).Cells(Columna).Value = Total.ToString End If

MsgBox("no asi no ")

End Sub

You might also like