Kattaleya Posted May 30, 2014 at 02:39 PM Report #557682 Posted May 30, 2014 at 02:39 PM 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?
bioshock Posted May 30, 2014 at 02:42 PM Report #557683 Posted May 30, 2014 at 02:42 PM Essa DataGridView tem um DataSet atribuído a ela?
Kattaleya Posted May 30, 2014 at 02:50 PM Author Report #557685 Posted May 30, 2014 at 02:50 PM Em 30/05/2014 às 16:42, bioshock disse: Essa DataGridView tem um DataSet atribuído a ela? EQTJ80r.png esta ai. Tem as listbox dps vao ficar escondidas
bioshock Posted May 30, 2014 at 02:57 PM Report #557686 Posted May 30, 2014 at 02:57 PM nome_do_dataset.Tables(0).DefaultView.RowFilter = "nome_da_coluna LIKE '%texto_a_pesquisar%'";
Kattaleya Posted May 30, 2014 at 03:11 PM Author Report #557689 Posted May 30, 2014 at 03:11 PM e isso vai confirmar ao ficheiros e tudo se existe? 🙂
bioshock Posted May 30, 2014 at 03:15 PM Report #557690 Posted May 30, 2014 at 03:15 PM Hum? O que esse código faz é filtrar pelo campo que pretendes, e, obviamente, depois de apanhado o campo ele mostra a linha a que se refere.
Kattaleya Posted May 30, 2014 at 03:18 PM Author Report #557691 Posted May 30, 2014 at 03:18 PM 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.
bioshock Posted May 30, 2014 at 03:29 PM Report #557692 Posted May 30, 2014 at 03:29 PM (edited) Tens duas soluções: 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. 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 May 30, 2014 at 03:30 PM by bioshock
Kattaleya Posted May 30, 2014 at 03:36 PM Author Report #557693 Posted May 30, 2014 at 03:36 PM o que é um indice? xD Eu disse que não era muito boa em programação :/
bioshock Posted May 30, 2014 at 03:40 PM Report #557695 Posted May 30, 2014 at 03:40 PM Não se ter muitos conhecimentos de programação não engloba ser-se preguiçoso e muito menos não conhecer o google. http://www.webopedia.com/TERM/I/index.html
Kattaleya Posted May 30, 2014 at 03:45 PM Author Report #557699 Posted May 30, 2014 at 03:45 PM xD ok
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now