Portal    Foro    Buscar    FAQ    Registrarse    Conectarse

Eliminar Un Control

Eliminar Un Control
Artículo
Responder citando    Descargar mensaje  
Mensaje Eliminar Un Control 
 
Hola chicos les consulto alguien me puede dar una mano..? Quiero eliminar unos controles creados de forma dinamica y la verdad no se como acceder a ellos para eliminarlos..
Desde ya muchas gracias..

Public kb As CheckBox
 
Public Sub Form_Open()
Dim a As Integer


TableView1.Rows.Count = 3
TableView1.Columns.Count = 3

' Vamos a crear los chekbox:

For a = 0 To TableView1.Rows.Max
With kb = New CheckBox(TableView1.Children[0]) As "ChkBox"
.X = TableView1[a, 0].X '+ TableView1[a, 0].W
.Y = TableView1[a, 0].y + TableView1[a, 0].H
.W = TableView1[a, 0].W
.H = TableView1[a, 0].H

'.Text = "On/Off"
.Name = a
End With
TableView1[a, 1].Text = a
Next

End


Public Sub Button1_Click()
Dim a As Integer

'Bucle para eliminar el control
For a = 0 To TableView1.Rows.Max - 1

 If TableView1[a, 2].Text = "1" Then

   TableView1.Rows.Remove(a)

   kb.Delete
  
 Endif
   kb.X = TableView1[a, 0].X
   kb.Y = TableView1[a, 0].y
Next
End

Este codigo me da un error de objeto inavalido...



 
Ricardo Prieto - Ver perfil del usuario Enviar mensaje privado  
Ricardo Prieto [ Lunes, 10 Octobre 2016, 00:22 ]
 


Eliminar Un Control
Comentarios
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
sube el código fuente....
iba a probar ese código pero ya veo que tengo que andar agregando controles y demás.

es mas cómodo y mejor para ayudar si compartís el código.

saludos



 
v3ctor - Ver perfil del usuario Enviar mensaje privado  
v3ctor [ Lunes, 10 Octobre 2016, 00:57 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
El que esta hay ahí es el código fuente..
Tendría que eliminar todos los checkbox que en el tableview columna 0, fila x tengan un valor 1.



 
Ricardo Prieto - Ver perfil del usuario Enviar mensaje privado  
Ricardo Prieto [ Lunes, 10 Octobre 2016, 01:08 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Ricardo Prieto escribió: [Ver mensaje]
Este codigo me da un error de objeto inavalido...


Porque tú eliminas el objeto con
kb.Delete

y luego intentas asignar un valor a una su propiedad:
kb.X = TableView1[a, 0].X
kb.Y = TableView1[a, 0].y

...pero el objeto ya no existe.


Bueno, yo propondría...
Public Sub Button1_Click()

  Dim a As Integer
  Dim ob As Object
  
   ob = TableView1.Children[0]

   For a = 0 To TableView1.Rows.Max - 1
     If TableView1[a, 1].Text = "1" Then
       TableView1.Rows.Remove(a)
       ob.Children[a].Delete
     Endif
   Next

   a = 0
  
   For Each kb In ob.Children
     kb.X = TableView1[a, 0].X
     kb.Y = TableView1[a, 0].y
     Inc a
   Next

End




 
última edición por vuott el Lunes, 10 Octobre 2016, 02:08; editado 3 veces 
vuott - Ver perfil del usuario Enviar mensaje privado  
vuott [ Lunes, 10 Octobre 2016, 01:44 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Gracias voutt voy a probarlo..



 
Ricardo Prieto - Ver perfil del usuario Enviar mensaje privado  
Ricardo Prieto [ Lunes, 10 Octobre 2016, 02:56 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Gracias voutt funciona a la perfeccion...!  



 
Ricardo Prieto - Ver perfil del usuario Enviar mensaje privado  
Ricardo Prieto [ Lunes, 10 Octobre 2016, 03:08 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Pregunto si uso directamente el tableview.children me tirar error..?

Public Sub Button1_Click()

  Dim a As Integer
  Dim ob As Object
  
   ob = TableView1.Children[0]

   For a = 0 To TableView1.Rows.Max - 1
     If TableView1[a, 1].Text = "1" Then
       TableView1.Rows.Remove(a)
       ob.Children[a].Delete
     Endif
   Next

   a = 0
  
   For Each kb In TableView1.Children -----> Aqui da error
     kb.X = TableView1[a, 0].X
     kb.Y = TableView1[a, 0].y
     Inc a
   Next

End
[/quote]



 
Ricardo Prieto - Ver perfil del usuario Enviar mensaje privado  
Ricardo Prieto [ Lunes, 10 Octobre 2016, 03:18 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Mira que os complicáis la vida...    



 
shordi - Ver perfil del usuario Enviar mensaje privado  
shordi [ Lunes, 10 Octobre 2016, 08:50 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Ricardo Prieto escribió: [Ver mensaje]
Pregunto si uso directamente el tableview.children me tirar error..?

For Each kb In TableView1.Children -----> Aqui da error
 


Porque tienes que identificar precisamente el objeto "Children" del TableView (en este caso el ScrollView) "que" contiene los objetos CheckBox creados (que asì son Children del Children del TableView).

TableView
-------|________ScrollView
------------------------------|_______CheckBox

Al escribir simplemente TableView.Children, tú buscas el "Children" del TableView, y no del ScrollView.

Podemos traducir "For Each kb In TableView1.Children" tambien asì:
Por cada CheckBox que es Children del TableView (...que está en el grupo de los Children del TableView)
........pero CheckBox no es un Children del TableView !



 
última edición por vuott el Lunes, 10 Octobre 2016, 09:59; editado 7 veces 
vuott - Ver perfil del usuario Enviar mensaje privado  
vuott [ Lunes, 10 Octobre 2016, 09:38 ]
Responder citando    Descargar mensaje  
Mensaje Re: Eliminar Un Control 
 
Ok gracias voutt por la paciencia y la explicación. Quería tener bien en claro el funcionamiento..



 
Ricardo Prieto - Ver perfil del usuario Enviar mensaje privado  
Ricardo Prieto [ Lunes, 10 Octobre 2016, 13:08 ]
Mostrar mensajes anteriores:    
 
Publicar nuevo tema  Responder al tema  Página 1 de 2
Ir a la página 1, 2  Siguiente
 

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 



 

cron