[RESOLVED] [2005] Edit Item In Checked ListBox(......help help)
I stripped part of my project and included where i need help.
ISSUE:
As in the attached sample, i have two checked listboxes ona form and a contextmenu for editing the items in the listboxes.
When i click on one or more items in the first Listbox, it brings the values related to the checked item in(Admin Level 1) to the Admin Level 2 listbox.
I populate and retrieve the values of the listboxes using an array class.
MAIN ISSUE:
When i populate (Admin Level 2 listbox) using the selectedIndexChanged Event for (Admin Level 1 listbox), i can't edit the items in the (listbox 1)!, yet i can edit the items in listbox 2!
To check this, try commenting out the routine that populates listbox 2 and then Edit the items in listbox 1. It works perfect, but when you uncomment it, it gives an error "Unable to cast object of type 'System.String' to type 'EditCheckedListBox.cls_ListComboItem'"! I get puzzled.
What am i getting wrong here. The SQL Statement is correct and it seems it gets called again.
Please help me.
Note: To Edit, right click an item in the listbox and click Edit.
I am sorry for not commenting out the code. But i presume its pretty
simple to understand for an average man
Last edited by maps; Nov 2nd, 2006 at 06:17 AM.
Reason: ...
Re: [2005] Edit Item In Checked ListBox(......help help)
Hi,
I found couple the errors in your code. In the edit sub, you were trying to replace a cls_ListComboItem object with a String object. It would've been OK if you don't use that item again (that's why you can edit items in listbox2, but it crashes when you edit items in listbox1). However, you want to update listbox2 after the edit, thus it requires the use of the newly edited item (which is now a string)... Trying to cast a string to cls_ListComboItem object blew the application.... So I fixed it for you.
Another minor problem is you forget to check for null objects in another sub. I fixed that for you too.
VB Code:
Sub EditItems(ByRef lstControl As CheckedListBox)
If lstControl.CheckedItems.Contains(lstControl.SelectedItem) Then ' Check WHETHER ITS SELECTED AND CHECKED.