Currymunch
Member
- Joined
- Jan 21, 2008
- Messages
- 13
- Programming Experience
- Beginner
Edit : title should read - Help with editing a value in a ListBox
Howdy all, I'm having a slight problem at the moment with setting up to edit a value in a listbox
When i have a value selected in a listbox and press edit, I aim to open another form with the details of the selected index already filled in. The ListBox is storing the ToString data about a class that i setup called CSpy(naming issues already highlighted in a previous post, it's to aid the marking apparently)

Image Below is the form. But i would like it to have the values entered already entered for an edit so in this case -- first name = joe, second name = Bloggs etc

I think it's going wrong when it tries to convert the Cspy to a string (if thats the case how do i extract the data in the listbox as a string so that i can maniplate it) or am I way off.
error ==>
'***********************************************
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'CSpy' to type 'String' is not valid.
'***********************************************
This is the culmination of my efforts thus far.
Form is loaded, if title bar = Edit Spy then try all that stuff below
'*****************************************************
'*The Code below aims to split the selected index of the listbox up by the '*commas.
'*****************************************************
Private Sub entrySpy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Me.Text = "Edit Spy" Then
Dim myArray(8) As String
myArray = Split(mainSpy1.spyList.Items(mainSpy1.spyList.SelectedIndex)), ",")
txtFirstName.Text = myArray(0)
txtSurname.Text = myArray(1)
txtCodeName.Text = myArray(2)
comboAge.Text = myArray(3)
comboSex.Text = myArray(4)
txtDmarks.Text = myArray(5)
txtSkills.Text = myArray(6)
txtBankNumber.Text = myArray(7)
End If
'*******************************************
Any ideas how i should proceed? Am I going up totally the wrong line of attack and should add a method to split up the listbox in the class?
Thanks in advance
Howdy all, I'm having a slight problem at the moment with setting up to edit a value in a listbox
When i have a value selected in a listbox and press edit, I aim to open another form with the details of the selected index already filled in. The ListBox is storing the ToString data about a class that i setup called CSpy(naming issues already highlighted in a previous post, it's to aid the marking apparently)

Image Below is the form. But i would like it to have the values entered already entered for an edit so in this case -- first name = joe, second name = Bloggs etc

I think it's going wrong when it tries to convert the Cspy to a string (if thats the case how do i extract the data in the listbox as a string so that i can maniplate it) or am I way off.
error ==>
'***********************************************
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'CSpy' to type 'String' is not valid.
'***********************************************
This is the culmination of my efforts thus far.
Form is loaded, if title bar = Edit Spy then try all that stuff below
'*****************************************************
'*The Code below aims to split the selected index of the listbox up by the '*commas.
'*****************************************************
Private Sub entrySpy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Me.Text = "Edit Spy" Then
Dim myArray(8) As String
myArray = Split(mainSpy1.spyList.Items(mainSpy1.spyList.SelectedIndex)), ",")
txtFirstName.Text = myArray(0)
txtSurname.Text = myArray(1)
txtCodeName.Text = myArray(2)
comboAge.Text = myArray(3)
comboSex.Text = myArray(4)
txtDmarks.Text = myArray(5)
txtSkills.Text = myArray(6)
txtBankNumber.Text = myArray(7)
End If
'*******************************************
Any ideas how i should proceed? Am I going up totally the wrong line of attack and should add a method to split up the listbox in the class?
Thanks in advance
Last edited: