terça-feira, 17 de outubro de 2017

Pesquisar registro em DataGridView - VB.NET

No botão pesquisar adicione;


1:  Function Pesquisa(QualGrid As DataGridView, Pesquisa As String) As Boolean  
2:      Dim str As String  
3:        
4:      Dim Res As Boolean = False  
5:      For Each linha As DataGridViewRow In QualGrid.Rows  
6:        If Not linha.IsNewRow Then  
7:          str = UCase(linha.Cells("PROPRIEDADE_NAME_DA_COLUNA_DO_GRID").Value.ToString)  
8:          If str.Contains(Pesquisa.ToUpper) Then  
9:            QualGrid.CurrentCell = linha.Cells("PROPRIEDADE_NAME_DA_COLUNA_DO_GRID")  
10:            'Achou  
11:            Res = True  
12:          End If  
13:        Else  
14:          'Não Achou  
15:          Res = False  
16:        End If  
17:      Next  
18:      Return(Res)  
19:    End Function  

Para chamar esta função;


1:  If Pesquisa(DataGridView1, "João") = True Then  
2:  End If  

Lembrando quem irá selecionar a linha se acha-la.

COMENTE

& Compartilhe

1 comentários:

 

Copyright © 2015 Projeto Programação

Distributed By My Blogger Themes | Designed by Templateism