No puedo llevar un combobox con un objeto
Publicado por Facundo (1 intervención) el 06/05/2019 20:49:09
Buenas, estoy practicando para un examen final en visual basic, tengo que hacer una aplicacion basica, cargar un combobox con un objeto y de ahi recorrer un datagrid con un for each, el tema es que no estoy pudiendo cargar bien los datos del objeto, cuando corro la aplicacion me muestra el nombre del proyecto y el nombre del objeto, no tengo idea que puede ser, probe usando el codigo de otro ejercicio que si me funciono, adjunto imagen y codigo, desde ya muchas gracias!
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Public Class Producto
Public Id As Integer
Public Nombre As String
End Class
Public Class Iva
Public Id As Integer
Public Nombre As String
Public Valor As Double
End Class
Public Class Form1
Dim dt As New DataTable
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim xProducto As New Producto
Dim xListProducto As New List(Of Producto)
Dim xIva As New Iva
Dim xListIva As New List(Of Iva)
Try
xProducto.Id = 0
xProducto.Nombre = "Seleccione Producto"
xListProducto.Add(xProducto)
xProducto = New Producto
xProducto.Id = 1
xProducto.Nombre = "Coca-cola"
xListProducto.Add(xProducto)
xProducto = New Producto
xProducto.Id = 2
xProducto.Nombre = "Agua"
xListProducto.Add(xProducto)
xProducto = New Producto
xProducto.Id = 3
xProducto.Nombre = "Fernet"
xListProducto.Add(xProducto)
Me.CmbProducto.DisplayMember = "Producto"
Me.CmbProducto.ValueMember = "Id"
Me.CmbProducto.DataSource = xListProducto
Catch ex As Exception
MessageBox.Show(ex.Message, "Error al cargar formulario", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Try
xIva.Id = 0
xIva.Nombre = "Seleccione iva"
xIva.Valor = 0
xListIva.Add(xIva)
xIva = New Iva
xIva.Id = 1
xIva.Nombre = "21"
xIva.Valor = 0.21
xListIva.Add(xIva)
xIva = New Iva
xIva.Id = 2
xIva.Nombre = "10"
xIva.Valor = 0.1
xListIva.Add(xIva)
xIva = New Iva
xIva.Id = 3
xIva.Nombre = "4"
xIva.Valor = 0.04
xListIva.Add(xIva)
Me.CmbIva.DisplayMember = "Nombre"
Me.CmbIva.ValueMember = "Id"
Me.CmbIva.DataSource = xListIva
Catch ex As Exception
MessageBox.Show(ex.Message, "Error al cargar formulario", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'cargo la estructura del datatable
dt.Columns.Add("CUIT", GetType(String))
dt.Columns.Add("Nombre", GetType(String))
dt.Columns.Add("Producto", GetType(String))
dt.Columns.Add("Cantidad", GetType(Integer))
dt.Columns.Add("Precio", GetType(Integer))
End Sub
Private Sub CmbNombre_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbProducto.SelectedIndexChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If Len(Me.TxtbCuil.Text) > 13 Then
Throw New Exception("El cuit no puede ser mayor a 13 caracteres")
End If
If Not IsNumeric(Me.TxtbPrecio.Text) Then
Throw New Exception("El campo precio debe ser numerico")
End If
If Not IsNumeric(Me.TxtbCantidad.Text) Then
Throw New Exception("El campo Cantidad debe ser numerico")
End If
If CmbProducto.SelectedIndex = 0 Then
Throw New Exception("Seleccione un producto")
End If
dt.Rows.Add(Me.TxtbCuil.Text, Me.TxtbNombre.Text, Me.CmbProducto.SelectedText, Me.TxtbCantidad.Text, Me.TxtbPrecio.Text)
Me.Grilla.DataSource = dt
Catch ex As Exception
MessageBox.Show(ex.Message, "Error al agregar venta", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim neto As Double = 0
Dim cantidadParcial As Integer = 0
Dim precioParcial As Integer = 0
Dim totalParcial As Integer = 0
For Each dgr As DataGridViewRow In Me.Grilla.Rows
cantidadParcial = dgr.Cells("Cantidad").Value
precioParcial = dgr.Cells("Precio").Value
totalParcial = (precioParcial * cantidadParcial)
neto = neto + totalParcial
Next
Dim ivaValor As Double = 0
Dim ivatotal As Double = 0
TxtNeto.Text = neto
TxtIva.Text = CmbIva.SelectedText
ivaValor = 0.04
ivatotal = (neto * ivaValor)
neto = neto + ivatotal
TxtIva.Text = ivatotal
TxtTotal.Text = neto
End Sub
Private Sub TxtbCuil_TextChanged(sender As Object, e As EventArgs) Handles TxtbCuil.TextChanged
End Sub
End Class
Valora esta pregunta
0