JosephEricDavis
asked on
Access 2007 VBA - Change values of listbox items
I have a listbox that is populated with multiple items, each having several columns worth of data. I create the listbox items originally through code as is shown below.
Later, based on user actions I would like to be able to change some of the values of the different listbox items.
I've tried using code like this...
selectedIndex = lstbxAttachments.ItemsSele cted.item( 0)
lstbxAttachments.Column(1, selectedIndex) = "Removed"
lstbxAttachments.Column(3, selectedIndex) = ""
lstbxAttachments.Column(5, selectedIndex) = -1
But I end up throwing an exception when I try to change them like this. Is there a better way to do this?
Later, based on user actions I would like to be able to change some of the values of the different listbox items.
I've tried using code like this...
selectedIndex = lstbxAttachments.ItemsSele
lstbxAttachments.Column(1,
lstbxAttachments.Column(3,
lstbxAttachments.Column(5,
But I end up throwing an exception when I try to change them like this. Is there a better way to do this?
Set rs = DataService.Contract_GetContractAttachmentsByContractID(editID)
While Not rs.EOF
strItem = CStr(rs("DocID")) + ";" + rs("DocDesc") + ";" + rs("Path") + ";" + rs("DocType") + ";" + CStr(rs("DocTypeID")) + ";1"
lstbxAttachments.AddItem (strItem)
rs.MoveNext
Wend
rs.Close
ASKER
I don't want to remove the item, I want to change the item. So the same item will look different to the user.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim i As Integer
For i = Listbox.ListCount - 1 To 0 Step -1
If Listbox.ItemData(i) = "hello world" Then
Listbox.RemoveItem i
Next i