Saludos, estoy desarrollando una aplicación en VB 2005 y tuve la necesidad de crear unos combobox en tiempo de ejecución, hasta ahi esta todo bien, pero ahora la pregunta mia es: ¿Como puedo trabajar con ellos?, es decir, quiero que al seleccionar un elemento de algun combo creado suceda algo, como hago eso?
Aquí les pongo el codigo de como creé los controles:
Código:
Private Sub ControlesParaFacturas(ByVal ListFacturas As ListBox)
Dim Num As Integer = ListFacturas.Items.Count
Dim xIniTB As Integer = 34
Dim yIniTB As Integer = 235
Dim xIniCB As Integer = 154
Dim yIniCB As Integer = 235
Dim xIniTt As Integer = 300
Dim yIniTt As Integer = 235
Dim Total As Double = 0
Dim Nombre As String
For i As Integer = 1 To Num
'Extraer los datos del Listbox
Dim dFact() As String = Split(ListFacturas.Items(i - 1), " | ")
'Agregar textbox
Dim txtBox As New TextBox
With txtBox
.Name = "txtFactura" & i
.Width = 100
.Height = 22
If i > 1 Then
yIniTB += 23
End If
.Location = New System.Drawing.Point(xIniTB, yIniTB)
.Text = dFact(0)
.ReadOnly = True
.BackColor = Color.Cornsilk
End With
Me.Controls.Add(txtBox)
'Agregar combobox
Dim cmbTP As New ComboBox
Dim Elementos() As String = {"PARCIAL", "TOTAL"}
With cmbTP
.Name = "cmbTP" & i
.Width = 121
.Height = 21
If i > 1 Then
yIniCB += 23
.Focus()
End If
.Location = New System.Drawing.Point(xIniCB, yIniCB)
.Items.AddRange(Elementos)
.SelectedIndex = 1
End With
Me.Controls.Add(cmbTP)
'Agregar controles para mostrar el total de la factura.
Dim txtTotal As New TextBox
With txtTotal
Nombre = "txtTotal" & i
.Name = Nombre
.Width = 100
.Height = 22
If i > 1 Then
yIniTt += 23
End If
.Location = New System.Drawing.Point(xIniTt, yIniTt)
.Text = dFact(1)
.TextAlign = HorizontalAlignment.Right
.ReadOnly = True
.BackColor = Color.Cornsilk
End With
Me.Controls.Add(txtTotal)
Total = Total + FormatNumber(txtTotal.Text, , , , TriState.False)
Next
Me.txtMontoCobrar.Text = FormatNumber(Total, 2, , , TriState.True)
End Sub