Valadas Posted February 19, 2009 at 10:29 AM Report Share #245505 Posted February 19, 2009 at 10:29 AM Boas pessoal, tenho um problema para ir buscar os dados à base de dados e preencher a listview nas respectivas colunas.... se me pudessem ajudar... tenho o seguinte codigo: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim db As New OleDbConnection(Gestao_Jogadores.My.Settings.ligacaobd) db.Open() Dim comandosql = "Select Nome_jogador, Clube, Posicao from Perfil_Jogadores, Clubes where Nome_jogador like'" + TextBox1.Text + "%'" Dim cmd As New OleDbCommand(comandosql, db) Dim dtr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) With Me.ListView1 .Columns.Add("Nome", 50, HorizontalAlignment.Left) .Columns.Add("Clube", 50, HorizontalAlignment.Left) .Columns.Add("Posicao", 50, HorizontalAlignment.Left) .FullRowSelect = True .GridLines = False .View = View.Details End With While dtr.Read() ListView1.Items.Add(dtr.Item(0)) End While dtr.Close() db.Close() end sub RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 10:52 AM Report Share #245508 Posted February 19, 2009 at 10:52 AM E dá algum erro? o que nao funciona? tenta alterar aquele ciclo para algo do genero: Dim itmX as ListViewItem While dtr.Read() itmX=new ListViewItem() itmX.Text= dtr.GetValue(0).ToString() For i as Integer =1 To i = dtr.FieldCount - 1 itmX.SubItems.Add(dtr.GetValue(i).ToString()) Next ListView1.Items.Add(itmX); End While EDIT: lol adicionei o code e o geshi There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
jpaulino Posted February 19, 2009 at 10:56 AM Report Share #245509 Posted February 19, 2009 at 10:56 AM Assim, e se estiver a funcionar, apenas te preenche a primeira coluna. Tens de fazer mais ou menos isto: Dim item As ListViewItem While dtr.Read() item = New ListViewItem item.Text = dtr.Item(0) item.SubItems.Add(dtr.Item(1)) item.SubItems.Add(dtr.Item(2)) Me.ListView1.Items.Add(item) End While Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 11:53 AM Author Report Share #245514 Posted February 19, 2009 at 11:53 AM Obrigado, ficou resolvido!!!! 😛 utilizei o código do jpaulino e deu!! RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 11:58 AM Report Share #245515 Posted February 19, 2009 at 11:58 AM Obrigado, ficou resolvido!!!! 😛 utilizei o código do jpaulino e deu!! 🙂 ainda bem mas tem atenção.. a unica difrenca entre o meu codigo e o dele e que ele apenas conta com os 3 campos que tu tens seleccionados... no meu codigo podes utilizar para qualquer select que ele vai listar todos os campos seleccionados 😄 E nao te esquecas de por resolvido no nome do tópico. Cumps There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 12:04 PM Author Report Share #245516 Posted February 19, 2009 at 12:04 PM 😄 ainda bem mas tem atenção.. a unica difrenca entre o meu codigo e o dele e que ele apenas conta com os 3 campos que tu tens seleccionados... no meu codigo podes utilizar para qualquer select que ele vai listar todos os campos seleccionados 😛 E nao te esquecas de por resolvido no nome do tópico. Cumps sim so utilizei o dele porque era mais simples e como estou no inicio foi o que percebi melhor... outra coisa, como faço para quando abrir o form da listview carregar todos os dados guardados na bd?? RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 12:06 PM Report Share #245518 Posted February 19, 2009 at 12:06 PM outra coisa, como faço para quando abrir o form da listview carregar todos os dados guardados na bd?? Como assim? consegues especificar mais um pouco? nao estou a conseguir entender o que queres :S There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 12:11 PM Author Report Share #245519 Posted February 19, 2009 at 12:11 PM Como assim? consegues especificar mais um pouco? nao estou a conseguir entender o que queres :S entao é assim, tenho uma form para pesquisa com a listview e ao abrir a form aparece vazia, e queria que aparecesse a listview ja com os dados da bd.... :S se desse.... RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 12:20 PM Report Share #245521 Posted February 19, 2009 at 12:20 PM entao basta colocares o codigo que tens no butao no Load do form 😛 so que tens de retirar o filtro da textbox 😄 There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 12:46 PM Author Report Share #245527 Posted February 19, 2009 at 12:46 PM entao basta colocares o codigo que tens no butao no Load do form 😄 so que tens de retirar o filtro da textbox 🙂 ja esta!! 😛 obrigado. ja agora nao sabe se da para clicar num registo na listview e abri-lo na respectiva form!? RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 12:49 PM Report Share #245529 Posted February 19, 2009 at 12:49 PM lolol o que queres abrir? 😛 There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 12:50 PM Author Report Share #245530 Posted February 19, 2009 at 12:50 PM lolol o que queres abrir? 😛 a form onde esta o registo que aparece na listview.... RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 01:27 PM Report Share #245536 Posted February 19, 2009 at 01:27 PM Inseres isto antes do inicio da classe: Imports System Imports System.Windows.Forms Imports System.Reflection Depois crias estas duas funções: Public Shared Function CreateObjectInstance(ByVal objectName As String) As Object Dim obj As Object Try If objectName.LastIndexOf(".") = -1 Then objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName End If obj = [Assembly].GetEntryAssembly.CreateInstance(objectName) Catch ex As Exception obj = Nothing End Try Return obj End Function Public Shared Function CreateForm(ByVal formName As String) As Form Return DirectCast(CreateObjectInstance(formName), Form) End Function Depois para abrires o form que queres e facil basta saberes o nome do Form e fazes: Dim frm As Form frm = CreateForm("Nome_do_Form") frm.ShowDialog() There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 05:55 PM Author Report Share #245579 Posted February 19, 2009 at 05:55 PM Dá erro na variavel frm, diz "declaration expected"... :S RV Link to comment Share on other sites More sharing options...
Hellblazer Posted February 19, 2009 at 06:00 PM Report Share #245581 Posted February 19, 2009 at 06:00 PM Dá erro na variavel frm, diz "declaration expected"... :S Nao consigo reproduzir o teu erro... Fizes-te tudo como eu disse ali? :S There are two ways to write error-free programs; only the third one works. Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 06:05 PM Author Report Share #245583 Posted February 19, 2009 at 06:05 PM Nao consigo reproduzir o teu erro... Fizes-te tudo como eu disse ali? :S sim sim fiz tudo exacto e o unico erro e aquele... a form a abrir é form2 e meti... :s RV Link to comment Share on other sites More sharing options...
jpaulino Posted February 19, 2009 at 09:09 PM Report Share #245638 Posted February 19, 2009 at 09:09 PM ja agora nao sabe se da para clicar num registo na listview e abri-lo na respectiva form!? Tu na listview tens os nomes dos forms, é isso ? Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 09:12 PM Author Report Share #245641 Posted February 19, 2009 at 09:12 PM Tu na listview tens os nomes dos forms, é isso ? nao, nao tenho.. :s RV Link to comment Share on other sites More sharing options...
jpaulino Posted February 19, 2009 at 09:14 PM Report Share #245644 Posted February 19, 2009 at 09:14 PM nao, nao tenho.. :s Então o que queres abrir ? Tens o registo e queres mostrar os detalhes desse registo através de um novo form ? Link to comment Share on other sites More sharing options...
Valadas Posted February 19, 2009 at 09:16 PM Author Report Share #245646 Posted February 19, 2009 at 09:16 PM Então o que queres abrir ? Tens o registo e queres mostrar os detalhes desse registo através de um novo form ? sim. eu tenho um form onde adiciono os registos, e outro form para fazer a pesquisa. Depois na pesquisa ao clicar no registo encontrado ir abrir o form onde o inseri... fiz-me entender? :s RV Link to comment Share on other sites More sharing options...
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