Jump to content
Sign in to follow this  
Paulo Jorge

arraylist

Recommended Posts

Paulo Jorge

Boa tarde, acabei de criar um programa sobre arraylist mas este não me está a dar correcto.

Não estou a conseguir listar direito na minha listview e nao estou a conseguir carregar direito alguém me explica porque ?

abaixo deixo o meu código

Public Class frmlistalogin

   Public Sub New()
       ' This call is required by the Windows Form Designer.
       InitializeComponent()
       ' Add any initialization after the InitializeComponent() call.
       Carregar_Dados()
   End Sub
   Private Sub EliminarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminarToolStripMenuItem.Click
       If lvLogin.SelectedItems.Count > 0 AndAlso MsgBox("Tem a certeza?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
           For Each i As ListViewItem In lvLogin.SelectedItems
               Lista_Login.Remove(i.Tag)
           Next
           Carregar_Dados()
       End If
   End Sub
   Private Sub AlterarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlterarToolStripMenuItem.Click
       If lvLogin.SelectedItems.Count > 0 Then
           Dim frm As New frmMtn_Login(lvLogin.SelectedItems(0).Tag)
           frm.ShowDialog()
           Carregar_Dados()
       End If
   End Sub
   Private Sub Carregar_Dados()
       lvLogin.Items.Clear()
       For Each i As login In Lista_Login
           Dim aux As New ListViewItem(i.Numero)
           aux.SubItems.Add(i.Usename)
           aux.SubItems.Add(i.Password)
           aux.SubItems.Add(i.Usename)
           aux.Tag = i
           lvLogin.Items.Add(aux)
       Next
       slblTotal.Text = "Total de login: " & lvLogin.Items.Count
   End Sub
   Private Sub lvAlunos_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvLogin.DoubleClick
       If lvLogin.SelectedItems.Count > 0 Then
           Dim frm As New frmMtn_Login(lvLogin.SelectedItems(0).Tag)
           frm.ShowDialog()
           Carregar_Dados()
       End If
   End Sub
   Private Sub lvAlunos_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lvLogin.KeyDown
       If lvLogin.SelectedItems.Count > 0 AndAlso e.KeyData = Keys.Delete AndAlso MsgBox("Tem a certeza?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
           For Each i As ListViewItem In lvLogin.SelectedItems
               Lista_Login.Remove(i.Tag)
           Next
           Carregar_Dados()
       End If
   End Sub
   Private Sub PesquisarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PesquisarToolStripMenuItem.Click
       Dim aux As String = InputBox("Username?", "Pesquisa")
       For Each i As ListViewItem In lvLogin.SelectedItems
           i.Selected = False
       Next
       For Each i As ListViewItem In lvLogin.Items
           If CType(i.Tag, login).Usename.ToLower = aux.ToLower Then i.Selected = True
       Next
   End Sub

End Class

deixo também o modulo

Imports System.IO
Module var_func
   Public Lista_Login As New ArrayList
   Public Sub Carregar()
       Dim umLogin As New login
       umLogin.Usename = umLogin.Usename
       umLogin.Password = ("sada")
       umLogin.Nivel = umLogin.Nivel
       umLogin.Numero = ("aas")


       Lista_Login.Add(umLogin)
       Dim fr As StreamReader = Nothing
       Try
           fr = New StreamReader(Application.StartupPath & "\Lista_Login.dat", System.Text.Encoding.Default)
           Dim linha As String
           linha = fr.ReadLine
           While linha <> Nothing
               linha = fr.ReadLine
               If linha IsNot Nothing Then
                   Lista_Login.Add(New login(linha))
               End If
           End While
           fr.Close()
           MsgBox("Dados carregados com sucesso!!!")
       Catch ex As Exception
           If fr IsNot Nothing Then fr.Close()
           MsgBox("Erro ao carregar os dados do ficheiro!" & vbNewLine & ex.Message)
       End Try
   End Sub

   Public Sub Gravar()
       Dim fw As StreamWriter = Nothing
       Try
           fw = New StreamWriter(Application.StartupPath & "\Lista_Login.dat", False, System.Text.Encoding.Default)
           fw.WriteLine("Username;Password;Nivel;Numero")
           For Each i As login In Lista_Login
               fw.WriteLine(i.Linha_Ficheiro)
           Next
           fw.Close()
           MsgBox("Dados gravados com sucesso!!!")
       Catch ex As Exception
           If fw IsNot Nothing Then fw.Close()
           MsgBox("Erro ao carregar os dados do ficheiro!" & vbNewLine & ex.Message)
       End Try
   End Sub

End Module

Edited by anolsi
Adicionado geshi

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • 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.