Ander5
asked on
adding items to a Listview problem
I wrote a program that manages serial keys, writes them to the registry in a strong encryption and reads them back etc. When I add an application to the listview, the first two go alright then each one I add afterwords makes one additional entry (2, then 3 etc). Below is the code when the add button is clicked:
=====
Private Sub add_application()
Dim i As Integer
Try
If appNameBox.Text = Nothing Then
MsgBox("Please enter an application name", MsgBoxStyle.OKOnly, "Missing Name")
appNameBox.Focus()
Exit Sub
ElseIf appSerialBox.Text = Nothing Then
MsgBox("Please enter a serial key", MsgBoxStyle.OKOnly, "Missing Serial")
appSerialBox.Focus()
Exit Sub
Else
apName = appNameBox.Text
apSerial = appSerialBox.Text
existing_application()
End If
appNameBox.Text = Nothing : appSerialBox.Text = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
saved = False
End Sub
Private Sub existing_application()
''weird..
Dim lvi As ListViewItem
If Not appList.Items.Count = 0 Then
' For i = 0 To appList.Items.Count - 1
For Each lvi In appList.Items
If apName = appList.Items.Item(i).Text Then
Select Case MsgBox("Previous entry found. Update it?", MsgBoxStyle.YesNo, "Update Entry")
Case MsgBoxResult.Yes
Dim item As New ListViewItem
item.Text = apName
item.SubItems.Add(apSerial )
appList.Items.Item(i).Sele cted = True
appList.Items.Remove(appLi st.Selecte dItems.Ite m(0))
appList.Items.Add(item)
Exit Sub
Case MsgBoxResult.No
Exit Sub
End Select
Else
Dim item As New ListViewItem
item.Text = apName
item.SubItems.Add(apSerial )
appList.Items.Add(item)
End If
Next
Else
Dim item As New ListViewItem
item.Text = apName
item.SubItems.Add(apSerial )
appList.Items.Add(item)
End If
saved = False
End Sub
=====
What did I do wrong?
=====
Private Sub add_application()
Dim i As Integer
Try
If appNameBox.Text = Nothing Then
MsgBox("Please enter an application name", MsgBoxStyle.OKOnly, "Missing Name")
appNameBox.Focus()
Exit Sub
ElseIf appSerialBox.Text = Nothing Then
MsgBox("Please enter a serial key", MsgBoxStyle.OKOnly, "Missing Serial")
appSerialBox.Focus()
Exit Sub
Else
apName = appNameBox.Text
apSerial = appSerialBox.Text
existing_application()
End If
appNameBox.Text = Nothing : appSerialBox.Text = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
saved = False
End Sub
Private Sub existing_application()
''weird..
Dim lvi As ListViewItem
If Not appList.Items.Count = 0 Then
' For i = 0 To appList.Items.Count - 1
For Each lvi In appList.Items
If apName = appList.Items.Item(i).Text
Select Case MsgBox("Previous entry found. Update it?", MsgBoxStyle.YesNo, "Update Entry")
Case MsgBoxResult.Yes
Dim item As New ListViewItem
item.Text = apName
item.SubItems.Add(apSerial
appList.Items.Item(i).Sele
appList.Items.Remove(appLi
appList.Items.Add(item)
Exit Sub
Case MsgBoxResult.No
Exit Sub
End Select
Else
Dim item As New ListViewItem
item.Text = apName
item.SubItems.Add(apSerial
appList.Items.Add(item)
End If
Next
Else
Dim item As New ListViewItem
item.Text = apName
item.SubItems.Add(apSerial
appList.Items.Add(item)
End If
saved = False
End Sub
=====
What did I do wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.