![triste](http://static.forosdelweb.com/fdwtheme/images/smilies/frown.png)
el código;
Código vb:
Ver original
Private Sub renovarBotones() ''Aqui verifico si se presiono para eliminar los ''botones creados anteriormente y no se esten ''amontonando con los de la otra consulta If accion = 1 Then ' Recorremos la colección de controles del formulario For Each ctrl As Control In Me.Controls ' Si el tipo de control es un Button If TypeOf ctrl Is Button Then ' Si se llama "x" If ctrl.Name = "x" Then ' Lo eliminamos de la colección Me.Controls.Remove(ctrl) 'AQUI VUELVO A LLAMAR AL METODO ,SI ELIMINO UN BOTON QUE HAGA 'OTRA REVISION SINO QUE NO HAGA NADA PORQUE YA NO HAY renovarBotones() End If End If Next 'Limpio la tabla productos para que no se incremente undataset.Tables("productos").Clear() End If End Sub Public Sub cargar_formulario_Productos(ByVal fam As String) conexion.ConnectionString = "Data Source=.\SQLEXPRESS11;AttachDbFilename=C:\VISUAL\TpvVigoSe\TpvVigo\Tpv.mdf;" & _ "Integrated Security=True;" & _ "Connect Timeout=30;" & _ "User Instance=True" 'Creo las variables que definen el area de botones por fila Dim bxf, contador As Integer 'Creo la variables que contendran las dimensiones de los botones Dim altoBoton, anchoBoton As Integer 'Creo las variables de los puntos en los cuales empiezo a pintar los botones Dim x, y As Integer '------------------------------------------------------------------------------------------- bxf = 9 'Por ejemplo defino 9 botones por fila contador = 0 anchoBoton = 54 altoBoton = 87 x = 10 y = 320 'AQUI HAGO LA RECURSIVIDAD PARA ELIMINAR BOTONES renovarBotones() ''-------------------------------------------------------------------------------------------------------- Dim conlumna As New DataColumn conlumna.ColumnName.Contains("Producto") cmd.Connection = conexion cmd.CommandText = "select Producto from Productos where NFamilia = " & fam & " ORDER BY Orden ASC" adapta.SelectCommand = cmd adapta.Fill(undataset, "Productos") For i As Integer = 0 To undataset.Tables("Productos").Rows.Count - 1 'Si alcanzo el maximo de columnas de la fila a pintar If contador = bxf Then 'seteo el valor del contador contador = 0 'doy la coordenada para que inicie otra fila para crear botones y = y + anchoBoton x = 10 End If Dim nuevobotonProd As New Button nuevobotonProd.BackColor = Color.Khaki nuevobotonProd.Name = "x" nuevobotonProd.Location = New Point(x, y) nuevobotonProd.Size = New Size(altoBoton, anchoBoton) nuevobotonProd.Text = undataset.Tables("Productos").Rows(i).Item(0).ToString() Me.Controls.Add(nuevobotonProd) 'Aumento contador de columnas contador = contador + 1 'aumento la coordenada para crear otro boton en la siguiente columna x = x + altoBoton Next End Sub Public Sub insertaparrillaventa() conexion.ConnectionString = "Data Source=.\SQLEXPRESS11;AttachDbFilename=C:\VISUAL\TpvVigoSe\TpvVigo\Tpv.mdf;" & _ "Integrated Security=True;" & _ "Connect Timeout=30;" & _ "User Instance=True" cmd.CommandText = "Insert Into GuardarVentas(NombreProducto,Cantidad,Euros) Select Productos.Producto, Productos.Consumo, Productos.Tarifa1 from Productos" adapta.SelectCommand = cmd adapta.Fill(undataset, "Productos,GuardarVentas")