Visual Basic.NET - Consulta DataGridView.

 
Vista:
Imágen de perfil de Ronaldo

Consulta DataGridView.

Publicado por Ronaldo (2 intervenciones) el 16/09/2014 05:47:28
Hola amigos tengo una consulta para ver si me pueden ayudar.Estoy realizando un filtro en un datagridview en donde utilizo el siguiente código para obtener un filtro dependiendo del valor de un Textbox reverenciado a una columna y ademas un combobox que me permite elegir si filtrar o no o filtrar, cuando comience con "x", que contenga "x", entre otros.


Private Sub Combo_Objeto_TextChanged(sender As Object, e As EventArgs) Handles Combo_Objeto.TextChanged
Aplicar_Filtro()
End Sub


Public Sub Aplicar_Filtro()
' filtrar por el campo Objeto

''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ret As Integer = Filtrar_DataGridView("NOMBRE_OBJETO", Me.Combo_Objeto.Text.Trim, BindingSource1, Me.DataGridView2, _
CType(Me.Combo_Condi_1.SelectedIndex, e_FILTER_OPTION))
If ret = 0 Then
' si no hay registros cambiar el color del txtbox
Me.Combo_Objeto.BackColor = Color.Red
Me.TextBox_Result.Text = ""
Else
Me.Combo_Objeto.BackColor = Color.White
sumar()
End If
' visualizar la cantidad de registros
' Me.Text = ret & " Registros encontrados
ExisteEnLista()

If Me.Combo_Objeto.Text = "" Then
Me.TextBox_Result.Text = ("")
End If

End Sub

Enum e_FILTER_OPTION
SIN_FILTRO = 0
CADENA_QUE_COMIENCE_CON = 1
CADENA_QUE_NO_COMIENCE_CON = 2
CADENA_QUE_CONTENGA = 3
CADENA_QUE_NO_CONTENGA = 4
CADENA_IGUAL = 5
End Enum


Function Filtrar_DataGridView(ByVal Columna As String, ByVal texto As String, ByVal BindingSource As BindingSource, ByVal DataGridView As DataGridView, _
Optional ByVal Opcion_Filtro As e_FILTER_OPTION = Nothing) As Integer

' verificar que el DataSource no esté vacio
If BindingSource1.DataSource Is Nothing Then
Return 0
End If

Try

Dim filtro As String = String.Empty

' Seleccionar la opción
Select Case Opcion_Filtro
Case e_FILTER_OPTION.CADENA_QUE_COMIENCE_CON
filtro = "like '" & texto.Trim & "%'"
Case e_FILTER_OPTION.CADENA_QUE_NO_COMIENCE_CON
filtro = "Not like '" & texto.Trim & "%'"
Case e_FILTER_OPTION.CADENA_QUE_NO_CONTENGA
filtro = "Not like '%" & texto.Trim & "%'"
Case e_FILTER_OPTION.CADENA_QUE_CONTENGA
filtro = "like '%" & texto.Trim & "%'"
Case e_FILTER_OPTION.CADENA_IGUAL
filtro = "='" & texto.Trim & "'"
End Select
' Opción para no filtrar
If Opcion_Filtro = e_FILTER_OPTION.SIN_FILTRO Then
filtro = String.Empty
End If

' armar el sql
If filtro <> String.Empty Then
filtro = "[" & Columna & "]" & filtro
End If

' asigar el criterio a la propiedad Filter del BindingSource
BindingSource.Filter = filtro
' enlzar el datagridview al BindingSource
DataGridView.DataSource = BindingSource.DataSource

' retornar la cantidad de registros encontrados
Return BindingSource.Count

' errores
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
End Try
Return 0
End Function



Ahora bien yo quiero hacer ese mismo filtro pero que también dependa del valor de otro textbox que estará referenciado a otra columna, es decir que el filtro final dependa de los valores que tenga los dos textbox.

Agradezco la ayuda que me puedan brindar.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Consulta DataGridView.

Publicado por omar (128 intervenciones) el 16/09/2014 19:42:18
1..- Puedes realizar un filtro y cargar los datos en un dataset. este filtro es por el primer textbox
2.- ya al ingresar un dato en el segundo textbox aplicaras un filtro al dataset que filtro la primera vez y muestras los datos en controles ya sea datagridview o listbox o treeview
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar