Jump to content

Recommended Posts

Posted

Olá, tenho uma datagridview que mostra as informações que estão em ficheiros , mas gostava de saber como filtrar essas informações na datagridview.

Por exemplo: Quero ver um cliente por isso vou pesquizar por um dos nomes dele e se houver aparece só esse cliente na datagridview.

Como faço isso?

Posted

nome_do_dataset.Tables(0).DefaultView.RowFilter = "nome_da_coluna LIKE '%texto_a_pesquisar%'";

desculap enganei-me, ´que não sou muito boa em programação , nao tenho dataset. nao estou a utilizar base de dados.

este é o codigo que usei para guardar a informação de cada clientes. uso ficheiros porque é mais do que um computador a utilizar o programa ao mesmo tempo.

' Cria uma pasta.

My.Computer.FileSystem.CreateDirectory(CurDir() & "\Clientes\" & codTB.Text)

'SUJEITO A ----------------------------------------------------------------------------------------------------------------------------------

My.Computer.FileSystem.CreateDirectory(CurDir() & "\Clientes\" & codTB.Text & "\cod")

' escrever e guardar texto

' Codigo Cliente

'X

escrever = My.Computer.FileSystem.OpenTextFileWriter(CurDir() & "\Clientes\" & codTB.Text & "\cod\codA.dat", True)

escrever.Write(codTB.Text)

escrever.Close()

. e para apresentar na datagridview é o seguinte codigo:

ListBox1.DataSource = (From folder In New IO.DirectoryInfo(CurDir() & "\Clientes").GetDirectories Select (folder.Name)).ToArray

For Each valor In ListBox1.Items

ListBox2.DataSource = (From folder In New IO.DirectoryInfo(CurDir() & "\Clientes\" & valor).GetDirectories Select (folder.Name)).ToArray

For Each valor2 In ListBox2.Items

DataGridView1.Rows.Add(System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\deveA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\modoA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\dossierA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\codA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nomeA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nomeB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\financasA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimentoA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nifA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\socialA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\financasB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimentoB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nifB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\socialB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nif1.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimento1.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nif2.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimento2.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nif3.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimento3.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nif4.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimento4.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nif5.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimento5.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nif6.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nascimento6.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\fiscalA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\telefoneA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\telefoneB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\emailA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\emailB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nibA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\nibB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\cpA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\atividadeA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\atividadeB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\cessacaoA.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\cessacaoB.dat"), System.IO.File.ReadAllText(CurDir() & "\Clientes\" & valor & "\cod\reservaA.dat"))

Next

Next

If ListBox1.SelectedItem = Nothing Then

MessageBox.Show("Não existem registos. Por favor crie um novo registo.")

Exit Sub

mas agora nao sei filtrar pelo campo que o utilizador quer e informar se tem esse registo ou nao.

Posted (edited)

Tens duas soluções:

  1. Em vez de adicionares as linhas directamente à DataGridView adicionas a uma DataTable. Os valores da DataTable são atribuídos a um DataSet que por sua vez é atribuído à DataGridView. Desta forma utilizas o código que te coloquei inicialmente.
  2. Terás de fazer um ciclo para percorrer todas as linhas da DataGridView, obténs o índice e trabalhas com ele.

For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells.Item(INDICE_DA_COLUNA).Value = "texto_a_pesquisar" Then
       Dim rowindex As Integer = row.Index
	' trabalha a informação
End If
End For
Edited by bioshock

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.