Hi. I'm actually making this very basic password manager and it has 2 listboxes and when i click the Add button it adds the name on the 1st listbox and all the rest on the 2nd listbox. The problem is that when i make more items in the first listbox and i click on of them they show all the other ones here's a picture of what i mean: http://puu.sh/49jHb.png << i just want to make it such that when an item is clicked it only shows the items related to the 1st item in the 1st listbox. So basically under yahoo it should only show Dave, test and hotmail it should show Ahmed, test

Anyone :D
thanks!

Recommended Answers

All 7 Replies

Show us your code.

Hi. Sorry for the late reply. I've just been busy with something but here's what i've got soo far:

Imports System.Text
Imports System.IO

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Check()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Try
        ListBox1.Items.Remove(ListBox1.SelectedItem.ToString)
    Catch ex As Exception
        Label2.Text = ex.Message
    End Try

End Sub
Public Sub Check()
    If String.IsNullOrEmpty(TextBox3.Text) Then
        Label2.Text = "Make sure to add the name of the account. e.g. Yahoo, Hotmail, YouTube"
    ElseIf String.IsNullOrEmpty(TextBox1.Text) Then
        Label2.Text = "Make sure to add your account name. Cannot enter blank space."
    ElseIf String.IsNullOrEmpty(TextBox2.Text) Then
        Label2.Text = "Make sure to add your account password. Cannot enter blank space."
    Else
        CreatePSW()

    End If
End Sub
Public Sub CreatePSW()

    Dim path As String = "C:\Users\Ahmed.C\Documents\" & TextBox3.Text & ".txt"
    Dim fs As FileStream = File.Create(path)
    Dim info As Byte() = New UTF8Encoding(True).GetBytes("Account For: " & TextBox3.Text & vbNewLine & "Account Name: " & TextBox1.Text & vbNewLine & "Account Password: " & TextBox2.Text)
    fs.Write(info, 0, info.Length)
    fs.Close()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Timer1.Start()
    My.Computer.FileSystem.CreateDirectory(Label1.Text & "PswManager\Accounts")
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label1.Text = Path.GetPathRoot(My.Application.Info.DirectoryPath)
End Sub

End Class

You haven't included your code for a handler for ListBox1 for a change in selection.

Why do you need a timer to repeatedly get a static value?

You should rename your controls so that the code is clearer.

You should add comments.

You have handlers for two buttons but I only see one on the form.

From now on please upload associated images to Daniweb. If you place them elsewhere and they eventually disappear then this thread loses information that makes it useful to others.

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ListBox1.Items.Add(TextBox1.Text)
        ListBox2.Items.Add(TextBox2.Text)
        ListBox2.Items.Add(TextBox3.Text)
    End Sub

Hi. I've added this code although it's just to add the items. But i want it so taht e.g. if i click Ahmed it should only show password and Hotmail like this: http://puu.sh/4dN3G.png instead it shows both items. password and yahoo should be under dave and not show it when i click Ahmed.

You have to add a handler to populate listbox2 with new data when you select an item in listbox1

Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    Dim lbx As ListBox = sender
    MsgBox("You selected " & lbx.SelectedItem)

    'add your code to clear and populate listbox2 here

End Sub

Thanks for the code but the thing is that i want to save the items in listbox2 so that when i click ahmed it only shows password and hotmail, and when i click dave it should only show password, yahoo.

Nevermind. I've got a work around and it works perfectly. Thanks for your time :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.