Question[help]Save to listbox

Posts 1–10 of 10 · Page 1 of 1
[help]Save to listbox
So i have textbox1 and textbox2.
textbox1 contains the name of a code for a game
textbox2 contains the code

and there is a save to listbox button.

so basically all i want to do is if the save to listbox button is clicked the will save the code to the listbox.

The item name will be the name of the code and when it is pressed the code will show in a msgbox.


[php]
Listbox1.Items.Add(Textbox1.Text)
Listbox1.Items.Add(Textbox2.Text)
[/php]

then save it with

[php]
Dim Lines() As String = My.Computer.FileSystem.ReadAllText("C:\SavedCodes. Txt").Split(vbCrLf)
ListBox1.Items.AddRange(Lines)

Dim OutText As String = ""
For Each S As String In ListBox1.Items
OutText &= S & vbCrLf
Next
My.Computer.FileSystem.WriteAllText("C:\SavedCodes .Txt", OutText, False)
[/php]

Suggestion By the way, multi column

can you teach me how to do multi column plz.
Use a listview. I prefer listviews =D

Code:
ListView1.View = View.Details
Add a few columns to your listview...

Add Main-/Subitems

Code:
If ListView1.FindItemWithText(Textbox1.Text) Is Nothing Then

            Dim lv As ListViewItem = ListView1.Items.Add(Textbox1.Text)
            'The remaining columns are subitems   
            lv.SubItems.Add(Textbox2.Text)
            lv.SubItems.Add(Textbox3.Text)
            lv.SubItems.Add(Textbox4.Text)
            lv.SubItems.Add(Textbox5.Text)
        Else
            MsgBox("You already added this server to your server list.")
        End If
Remove selected

Code:
  ListView1.Items.Remove(ListView1.FocusedItem)
Save listview

Code:
Dim Fb As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

        Dim FS As New System.IO.FileStream(Application.StartupPath & "\listview.txt", IO.FileMode.Create)
        Fb.Serialize(FS, New ArrayList(ListView1.Items))
        FS.Close()

Load listview

Code:
Try
            Dim Fb2 As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            Dim FS2 As New System.IO.FileStream(Application.StartupPath & "\listview.txt", IO.FileMode.Open)
            ListView1.Items.AddRange(Fb2.Deserialize(FS2).ToArray(GetType(ListViewItem)))
            FS2.Close()
        Catch ex As Exception

        End Try
hey blubb thanks for your method.

but when i tried this:
Code:
If ListView1.FindItemWithText(Textbox1.Text) Is Nothing Then

            Dim lv As ListViewItem = ListView1.Items.Add(Textbox1.Text)
            'The remaining columns are subitems   
            lv.SubItems.Add(Textbox2.Text)
            lv.SubItems.Add(Textbox3.Text)
            lv.SubItems.Add(Textbox4.Text)
            lv.SubItems.Add(Textbox5.Text)
        Else
            MsgBox("You already added this server to your server list.")
        End If
the textbox2.text does not appear anyway in the listview.
Do you have enough columns?
how do you make more columns.
Click on your listview > Take a look at the Properties > 'Columns' > Add Column


Programatically add columns with

[php]
ListView1.View = View.Details
'First part is name of column , This part is column width, this is the alignment of 'the column
ListView1.Columns.Add("Name Of Column", 20, HorizontalAlignment.Left)
[/php]
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us