Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/10/2010, 16:26
Avatar de xjuanch0x
xjuanch0x
 
Fecha de Ingreso: septiembre-2009
Mensajes: 125
Antigüedad: 14 años, 8 meses
Puntos: 1
Respuesta: Dar evento a un array de controles

Código vb:
Ver original
  1. Sub CARGAR_MENU()
  2.         Dim dv As New DataView(CLASE_SUBMENU.LISTAR_SUBMENU("Usp_Listar_Menu_02"))
  3.         Dim cantidad As Integer = dv.Count
  4.         Dim x As Integer = 3, y As Integer = 3
  5.         If cantidad > 0 Then
  6.             For i As Integer = 0 To cantidad - 1
  7.                 ReDim Preserve ARBOL(i)
  8.                 ARBOL(i) = New TreeView
  9.                 ARBOL(i).Name = dv.Item(i)(0)
  10.                 ARBOL(i).Nodes.Add(Trim(dv.Item(i)(1)))
  11.                 ARBOL(i).CheckBoxes = True
  12.                 ARBOL(i).BorderStyle = BorderStyle.None
  13.                 ARBOL(i).BackColor = System.Drawing.SystemColors.Control
  14.                 ARBOL(i).SetBounds(x, y, 172, 152)
  15.  
  16.  'Con esto agregas el mismo manejador para todos controles dentro del  'array
  17.                AddHandler  ARBOL(i).AfterCheck , AddressOf AfterCheckManejador
  18.  
  19.                 Me.pnMenu.Controls.Add(ARBOL(i))
  20.                 x += 182
  21.                 Dim codigo As String = Trim(dv.Item(i)(0))
  22.                 Dim dv2 As New DataView(CONSULTAR(codigo))
  23.                 Dim cant2 As Integer = dv2.Count
  24.                 If cant2 > 0 Then
  25.                     For j As Integer = 0 To cant2 - 1
  26.                         ARBOL(i).Nodes(0).Nodes.Add(dv2.Item(j)("cod_opc"), StrConv(Trim(dv2.Item(j)("nom_opc")), VbStrConv.ProperCase))
  27.                     Next
  28.                 End If
  29.                 ARBOL(i).ExpandAll()
  30.                 dv2.Dispose()
  31.             Next
  32.         End If
  33.         dv.Dispose()
  34.     End Sub



Con este código agregas el manejador a cada uno de los controles dentro de la colección de objetos.
__________________
Juan David Torres Vasquez
[email protected]
Microsoft Certified Technology Specialist (MCTS)
DCE Platinum en Visual C# y VB.NET