You are on page 1of 2

Public Class Form1

Dim x(20, 20) As Integer


Dim y(400) As Integer
Dim f, c As Integer
Private Sub TxtFilas_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtFilas.TextChanged
If Trim(TxtFilas.Text) <> "" And Trim(TxtColumnas.Text) <> "" Then
BtnLLenar.Visible = True
Else
BtnLLenar.Visible = False
End If
End Sub
Private Sub TxtColumnas_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtColumnas.TextChanged
If Trim(TxtFilas.Text) <> "" And Trim(TxtColumnas.Text) <> "" Then
BtnLLenar.Visible = True
Else
BtnLLenar.Visible = False
End If
End Sub
Private Sub BtnLLenar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnLLenar.Click
Dim i, j As Integer
pintar()
For i = 0 To f - 1
For j = 0 To c - 1
x(i, j) = InputBox("Ingreso datos", "Ingrese elemento " & i & "," & j & " : ")
DGV1.Item(j, i).Value = x(i, j)
Next
Next
BtnLimpiar.Visible = True
End Sub
Sub pintar()
f = Val(TxtFilas.Text)
c = Val(TxtColumnas.Text)
DGV1.ColumnCount = c
DGV1.RowCount = f
End Sub
Private Sub BtnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnLimpiar.Click
DGV1.Columns.Clear()
TxtFilas.Clear()
TxtColumnas.Clear()
BtnLimpiar.Visible = False
BtnLLenar.Visible = False
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
'PERMITE AUTOAJUSTAR ANCHO DE CELDAS
DGV1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
'PERMITE AUTOAJUSTAR alto DE CELDAS
DGV1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
'PERMITEN INTERCALAR COLOR
DGV1.RowsDefaultCellStyle.BackColor = Color.LightBlue
DGV1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
'cambiar el tipo y tamao de letra
DGV1.DefaultCellStyle.Font = New Font("Microsoft Sans Serif", 20)
End Sub
Private Sub BtnAuto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnAuto.Click
Dim i, j As Integer
Randomize()
f = Rnd() * 9 + 1
c=f
DGV1.ColumnCount = c
DGV1.RowCount = f
For i = 0 To f - 1
For j = 0 To c - 1
x(i, j) = Rnd() * 200 - 50
DGV1.Item(j, i).Value = x(i, j)
Next
Next
BtnLimpiar.Visible = True
End Sub
End Class

You might also like