By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Edit item value in an unbound list box

100+
P: 759
Hello !
Please, be patient with me :) but I spend 2 hours to find a way to do that with no success.

So:
I have an unbound list box. Only one column.
I fill this list using .AddItem command.
Now I wish to modify the value for item(n).

Oh, of course I can remove this item then insert other one in the same position (index) in the list with the new value.

But... is no solution to edit that item ?

Thank you !
Mar 19 '12 #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,314
Very interesting question.

Unfortunately, I believe the answer is "No". .Itemdata(), which might otherwise have been a viable approach, is a ReadOnly property, and I can find no other approach that might work (other than the obvious one of removing then re-adding the entry of course).
Mar 19 '12 #2

100+
P: 759
Because I can't find a solution to directly edit that damned item, I have developed a piece of code to do that:
Expand|Select|Wrap|Line Numbers
  1. Private Function ModifyItemInList(LstBx As ListBox, NewValue As String, R As Long, Optional C As Long = 0) As Boolean
  2. 'C > 0 is used for multicolumns list boxes
  3. On Error GoTo Ex
  4.     ModifyItemInList = False
  5. Dim SplitedRowSource
  6.     SplitedRowSource = Split(LstBx.RowSource, ";")
  7.     'Modify item
  8.     SplitedRowSource(R * LstBx.ColumnCount + C) = NewValue
  9. 'Create the new RowSource
  10. Dim NewRowSource As String, i As Long
  11.     For i = 0 To UBound(SplitedRowSource)
  12.         NewRowSource = NewRowSource & SplitedRowSource(i) & ";"
  13.     Next i
  14.     'Remove last ";"
  15.     NewRowSource = Left(NewRowSource, Len(NewRowSource) - 1)
  16.     'Update
  17.     LstBx.RowSource = NewRowSource
  18.  
  19.     ModifyItemInList = True
  20. Exit Function
  21.  
  22. Ex:
  23.     ModifyItemInList = False
  24. End Function
But more questions has been raised in this time.
So please take a look to this thread:
http://bytes.com/topic/access/answer...oo#post3711825
Mar 26 '12 #3

NeoPa
Expert Mod 15k+
P: 31,314
I suggest you use the simpler method of romoving and adding the item using .RemoveItem() and .AddItem() now it's clear how that can work (See linked thread).
Mar 26 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.