ListView and Registry Key

  • Thread starter Thread starter Laserson
  • Start date Start date
L

Laserson

Hi! How can i save all ListView items into registry key with Multistring
type and then extract them again and add to ListView?
 
Not a great example but you'll get the idea

You will need to add your own error trapping

Import Microsoft.Win32

In Sub New add this:

SetupListView()

Add a Listview (ListView1) & 5 buttons:

Private Sub SetupListView()
With ListView1
.Columns.Add("Test Column", 100, HorizontalAlignment.Left)
.View = View.Details
End With
End Sub

Private Sub ClearListView()
ListView1.Items.Clear()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strItems() As String = {"One", "Two", "Three", "Four", "Five"}
For Each strItem As String In strItems
ListView1.Items.Add(strItem)
Next
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ClearListView()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim strItem As String
Dim i As Integer
For i = 0 To ListView1.Items.Count - 1
strItem += ListView1.Items(i).Text
strItem += ";"
Next
strItem = strItem.TrimEnd(";")
Dim reg As RegistryKey =
Registry.CurrentUser.CreateSubKey("Software\Test")
reg.SetValue("Items", strItem)
If Not reg Is Nothing Then reg.Close()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
ClearListView()
Dim reg As RegistryKey =
Registry.CurrentUser.OpenSubKey("Software\Test", False)
Dim strItems As String = reg.GetValue("Items", "")
Dim strParts() As String = strItems.Split(";")
For i As Integer = 0 To strParts.GetUpperBound(0)
ListView1.Items.Add(strParts(i))
Next
If Not reg Is Nothing Then reg.Close()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Application.Exit()
End Sub

I hope this helps,

Newbie Coder
 
Back
Top