Autor Tema: [DUDA] - Filtrar DataGrid  (Leído 2854 veces)

0 Usuarios y 1 Visitante están viendo este tema.

omarinho23

  • Megabyte
  • ***
  • Mensajes: 105
  • Reputación: +0/-1
    • Ver Perfil
[DUDA] - Filtrar DataGrid
« en: Octubre 29, 2010, 12:16:38 pm »
alguien sabe como hacerlo de manera simple un filtro por 1 campo (ejemplo : nombre)
e buscado pero solo encuentro ejemplos de filtros enlazados con la Conex

mi idea es un filtro q se enlaze con la conexion q yo ponga alguien sabe alguna manera?
Gracias


PDT LO SIENTO ME EKIVOQUE DE POST xD ALGUIEN LO PUEDE PASAR A PROGRAMACION - VISUAL BASIC
;P GRACIAS!
« última modificación: Octubre 29, 2010, 12:20:44 pm por omarinho23 »

wolf_kof

  • Visitante
Re:[DUDA] - Filtrar DataGrid
« Respuesta #1 en: Octubre 29, 2010, 12:27:08 pm »

No se si esto te ayudaria... yo lo hago con ADO y con un Listview de CodeJock pero es lo mismo para un Listview Normal

Modulo:
Código: (VB) [Seleccionar]
option explicit
Global Data As New ADODB.Connection

Sub Main()
    llamar
    conectar
    login.Show
End Sub

Sub llamar()
Open App.Path & "\conex.txt" For Input As #1
Line Input #1, conex
End Sub

Sub conectar()
Data.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & conex & "\BD\BD.accde;Persist Security Info=False;Jet OLEDB:Database Password=0123456789"
End Sub

Esta es la foto del Formulario de la Explicación



Este es el codigo del Formulario: (Miralo bien hay varios filtrados)

Código: (VB) [Seleccionar]
Option Explicit
Dim nivel As New ADODB.Recordset
Dim estado, ccontraseña As String


Sub rellenar()
    ListView1.ColumnHeaders.Clear
    ListView1.ListItems.Clear
   
    ListView1.ColumnHeaders.Add 1, , "Ciclo", 800
    ListView1.ColumnHeaders.Add 2, , "Nivel", 4000
   
    Do Until nivel.EOF
            ListView1.ListItems.Add 1, , nivel!ciclo
            ListView1.ListItems(1).ListSubItems.Add 1, , nivel!nivel
    nivel.MoveNext
    Loop
   
End Sub

Private Sub buscar_Change()
If buscar.Text <> "" Then
    If v1.Value = True Then
    nivel.Filter = "ciclo like '%" & buscar.Text & "%'"
    rellenar
    End If
    If v2.Value = True Then
    nivel.Filter = "nivel like '%" & buscar.Text & "%'"
    rellenar
    End If
Else
    nivel.Filter = ""
    nivel.Requery -1
    rellenar
End If
End Sub

Private Sub Form_Load()
Me.Top = 50
nivel.Open "Select * from niveles", Data, adOpenDynamic, adLockOptimistic
TC.SelectedItem = 0
rellenar
End Sub

Private Sub Form_Unload(Cancel As Integer)
nivel.Close
Set nivel = Nothing
End Sub

Private Sub ListView1_DblClick()
On Error GoTo list
    If ListView1.SelectedItem.ListSubItems(1).Text <> "Programador" Then
        nivel.Filter = "ciclo = '" & ListView1.SelectedItem & "' and nivel = '" & ListView1.SelectedItem.ListSubItems(1) & "'"
        ccontraseña = nivel!Id
        cargar
        estado = "Editar"
        t1.Enabled = True
        TC.SelectedItem = 0
        t1.SetFocus
    End If
Exit Sub
list:

End Sub

Sub cargar()
On Error Resume Next
limpiar
t1.Text = nivel!ciclo
t2.Text = nivel!nivel
t3.Text = nivel!observaciones
End Sub

Private Sub PushButton1_Click()
limpiar
t1.Enabled = True

estado = "Nuevo"
TC.SelectedItem = 0
t1.SetFocus
t1.Text = Year(Date)
t1.SelStart = 0
t1.SelLength = 4
End Sub

Private Sub PushButton2_Click()
If estado = "Nuevo" Then
    nivel.AddNew
    nivel!ciclo = t1.Text
    nivel!nivel = t2.Text
    nivel!observaciones = t3.Text
    nivel.Update
    nivel.Requery -1
    rellenar
End If
If estado = "Editar" Then
    nivel.Filter = "Id = '" & ccontraseña & "'"
    nivel!ciclo = t1.Text
    nivel!nivel = t2.Text
    nivel!observaciones = t3.Text
    nivel.Update
    nivel.Filter = ""
    nivel.Requery -1
    rellenar
End If
limpiar
t1.Enabled = False
estado = "Guardar"
End Sub

Private Sub PushButton3_Click()
limpiar
t1.Enabled = False
estado = "Cancelar"
End Sub

Private Sub PushButton4_Click()
If estado = "Editar" Then
    nivel.Filter = "id = '" & ccontraseña & "'"
    nivel.Delete
    nivel.Filter = ""
    nivel.Requery -1
    limpiar
    t1.Enabled = False
    rellenar
    estado = "Eliminar"
End If
End Sub

Private Sub PushButton5_Click()
Unload Me
End Sub
Sub limpiar()
t1.Text = ""
t2.Text = ""
t3.Text = ""
End Sub

Private Sub v1_Click()
buscar_Change
End Sub

Private Sub v2_Click()
buscar_Change
End Sub