Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/11/2011, 09:37
Avatar de rikakashi
rikakashi
 
Fecha de Ingreso: julio-2011
Mensajes: 226
Antigüedad: 13 años, 2 meses
Puntos: 33
Sonrisa Respuesta: Limpiar todos los textbox de un formulario

Yo lo hacia de forma similar pero para ello hay que llamar todos los controles en cada contenedor... usaba un codigo como este solo que en lugar de enable seria .tex=nothing

Código vb:
Ver original
  1. Dim c As Control
  2.         Dim g As Control
  3.         Dim p As Control
  4.  
  5.         For Each p In TabPage1.Controls
  6.             If TypeOf p Is Panel Then
  7.                 For Each g In p.Controls
  8.                     If TypeOf g Is GroupBox Then
  9.                         For Each c In g.Controls
  10.                             If TypeOf c Is TextBox Then
  11.                                 c.Enabled = True
  12.                             ElseIf TypeOf c Is ComboBox Then
  13.                                 c.Enabled = True
  14.                             ElseIf TypeOf c Is CheckBox Then
  15.                                 c.Enabled = True
  16.                             End If
  17.                         Next
  18.                     End If
  19.                 Next
  20.             End If
  21.         Next

pero tambien pudieras hacer un arreglo de todos tus textbox y despues un metodo para recorrer el arreglo ahora uso este metodo ya que valido todos mis controles

Código vb:
Ver original
  1. Public Sub limpiar1()
  2.         'LIMPIA LOS CONTROLES DE LA PRIMERA PESTAÑA
  3.        Dim arr_con_tp1() As Control = {txt_nom_completo, txt_1_nom, txt_2_nom, txt_1_ap, txt_2_ap, txt_rfc, _
  4.                                             txt_calle, txt_num_int, txt_num_ext, txt_limite, txt_num_locker, _
  5.                                             txt_fecha_alta, dtp_fecha_aniversario, dtp_fecha_cumpleaños, txt_fecha_ult_acc, txt_fecha_ult_comentario, txt_fecha_ult_consumo, txt_fecha_ult_pago, _
  6.                                             txt_valordecuota, txt_dep_garantia, txt_num_locker, _
  7.                                             cmb_titulo, cmb_edocivil, cmb_ptocardinal, cmb_pais, cmb_estado, cmb_ciudad, cmb_colonia, _
  8.                                             rad_fisico, chk_inha_cred, chk_tarj_credito, chk_cargo_aut, chk_factura, chk_carga_intereses, chk_consumo_minimo_salas, _
  9.                                             chk_notif_cxc, chk_notif_nf, chk_notif_np, _
  10.                                             pic_foto, pic_firma, txt_edad, txt_tipo_tarjeta, txt_num_tarj, dtp_fecha_aniversario, dtp_fecha_cumpleaños}
  11.         limpiacontroles(arr_con_tp1)
  12.          End Sub

Código vb:
Ver original
  1. Public Sub limpiacontroles(ByVal arr_con_tp1_1() As Control)
  2.         'REGRESAR EL CONTROL A UN FORMATO INICIAL SIN TEXTO NI ELEMENTOS
  3.        For j As Integer = 0 To arr_con_tp1_1.Length - 1
  4.             If (TypeOf arr_con_tp1_1(j) Is TextBox) Then               'SI ES TEXTBOX
  5.                CType(arr_con_tp1_1(j), TextBox).Text = Nothing
  6.             ElseIf (TypeOf arr_con_tp1_1(j) Is CheckBox) Then          'SI ES CHECKBOX
  7.                CType(arr_con_tp1_1(j), CheckBox).Checked = False
  8.             ElseIf (TypeOf arr_con_tp1_1(j) Is RadioButton) Then       'SI ES RADIOBUTOON
  9.                CType(arr_con_tp1_1(j), RadioButton).Checked = False
  10.             ElseIf (TypeOf arr_con_tp1_1(j) Is DateTimePicker) Then      'SI ES DATETIMEPICKER
  11.  
  12.                 If CType(arr_con_tp1_1(j), DateTimePicker).Name <> "dtp_fecha_aniversario" Then
  13.                     CType(arr_con_tp1_1(j), DateTimePicker).Value = CType(arr_con_tp1_1(j), DateTimePicker).MaxDate
  14.                     CType(arr_con_tp1_1(j), DateTimePicker).Format = DateTimePickerFormat.Custom
  15.                     CType(arr_con_tp1_1(j), DateTimePicker).CustomFormat = "dd/MMM/yyyy"
  16.                 ElseIf CType(arr_con_tp1_1(j), DateTimePicker).Name = "dtp_fecha_cumpleaños" Then
  17.                     CType(arr_con_tp1_1(j), DateTimePicker).Value = Date.Now.Day & "/" & Date.Now.Month & "/" & (Date.Now.Year - 18)
  18.                     CType(arr_con_tp1_1(j), DateTimePicker).Format = DateTimePickerFormat.Custom
  19.                     CType(arr_con_tp1_1(j), DateTimePicker).CustomFormat = "dd/MMM/yyyy"
  20.                 End If
  21.  
  22.             ElseIf (TypeOf arr_con_tp1_1(j) Is PictureBox) Then        'SI ES PICTUREBOX
  23.                If CType(arr_con_tp1_1(j), PictureBox).Name = "pic_foto" Or CType(arr_con_tp1_1(j), PictureBox).Name = "pic_adi_foto" Then
  24.                     CType(arr_con_tp1_1(j), PictureBox).ImageLocation = rutaimagenes & rutafotos & "\foto.png"
  25.                 ElseIf CType(arr_con_tp1_1(j), PictureBox).Name = "pic_firma" Then
  26.                     CType(arr_con_tp1_1(j), PictureBox).ImageLocation = rutaimagenes & rutafirmas & "\firma.png"
  27.                 ElseIf CType(arr_con_tp1_1(j), PictureBox).Name = "pic_adi_foto" Then
  28.                     CType(arr_con_tp1_1(j), PictureBox).ImageLocation = rutaimagenes & rutafotosadi & "\foto.png"
  29.                 End If
  30.             ElseIf (TypeOf arr_con_tp1_1(j) Is ComboBox) Then       'SI ES COMBOBOX
  31.                CType(arr_con_tp1_1(j), ComboBox).Items.Clear()
  32.                 CType(arr_con_tp1_1(j), ComboBox).Text = Nothing
  33.                 CType(arr_con_tp1_1(j), ComboBox).Refresh()
  34.                 End If
  35.         Next
  36.     End Sub



y cuando quiera limpiar solo llamo la funcion
Código vb:
Ver original
  1. limpiar()
y listo
__________________
la programación es tan grande como la imaginación (+.+)