Ejemplo: Desarrollar una plicacion de windows con un data DataGridView.
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Not IsNumeric(txtCantidad.Text) Or cmbTipo.Text = String.Empty Then
MsgBox("Debe introducir una cantidad y seleccionar el tipo")
txtCantidad.Focus()
Else
Dim cant As Integer = txtCantidad.Text
Dim tipo As String = cmbTipo.Text
Dim prec As Decimal
Dim subt As Decimal
If tipo = "Negro" Then
prec = 0.05
Else
prec = 0.15
End If
subt = cant * prec
DataGridView1.Rows.Add(cant, tipo, prec, subt)
Dim total As Decimal = 0
For f = 0 To DataGridView1.Rows.Count - 1
total = total + DataGridView1.Rows(f).Cells(3).Value
Next
txtTotal.Text = FormatCurrency(total, 2)
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
DataGridView1.Rows.Clear()
txtCantidad.Clear()
cmbTipo.SelectedIndex = -1
txtTotal.Clear()
txtCantidad.Focus()
End Sub
Private Sub txtCantidad_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtCantidad.KeyPress
If InStr("0123456789", e.KeyChar) = False Then
If Asc(e.KeyChar) <> 8 Then
e.Handled = True
End If
End If
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
End
End Sub
End Class
No hay comentarios:
Publicar un comentario