Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chaging Values In ListBox

Status
Not open for further replies.

Creeder

Programmer
Jul 5, 2000
110
MY
Hi all,

Let's say i have a listbox which i add the items using THISFORM.list1.AddItem(<value>). Then i would like to modify the DisplayValue of the 3rd Item in the list? How would i do that? DO i need to pass the ListIndex?

Thanks

Yue Jeen

[sig][/sig]
 
When you call AddItem, you can optionally specify the nIndex; if you do that, you'll naturally know the index of the item you just added. You can also grab the index of the last added item with the List.NewIndex property. [sig]<p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br> [/sig]
 
Hi Robert,

Thanks for replying. However i am still facing the problem of manually changing the display value of the 3rd (or another) item.

Eg, I have a Textbox, command button and a listbox on my form. The listbox currently consist of 5 items, all using the additems method.

Let's say i type 'TEST' in the textbox and then select the 3rd item in the listbox, and when i click the command button i want to change the current displayvalue of the item in the list box to 'TEST'.

How do i reference that?
Should it be something like

THISFORM.list1.ListItem(<id>).DisplayValue = THISFORM.text1.value

unless there's no way to that except removing and readding another item?

Thanks in advance.

Yue Jeen
[sig][/sig]
 
Errr...uhhh....this is one of those things where you initially say of course you can do that, but then after investigation you find that, if you can do it, I have no idea how.

The clue was running the form, then opening our trusty Swiss Army (tm) Debugger and putting _screen.activeform in the Watch window. Expanding _screen.activeform, then .List1, we see the absence of any &quot;controls&quot; type collection or array. For an example of what I was looking for, run a form that has a grid, then look in the debugger's Watch window under the grid and you'll see lots of &quot;+&quot; expandable controls collections.

So Yue, my only advice is to work around it: make the RowSource for the list an array, and simply change that array element's contents and refresh the List. [sig]<p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br> [/sig]
 
Hi Robert,

I don't think there's a way to manually change the displayvalue of an item in a listbox if the item was added using the additem method in the first place. I guess i'll be using an array :) Thanks again robert :)

Yue Jeen [sig][/sig]
 
Hi Yue Jeen,

If you dont mind me asking, why are trying to avoid the RemoveItem/AddItem method?

WITH THISFORM
.LockScreen = .T. && if you're worried the user will see a flicker
lnIndex = .MyListBox.ListIndex
.MyListBox.RemoveItem(lnIndex)
.MyListBox.AddItem('My New Item',lnIndex)
.LockScreen = .F.
ENDWITH

Just curious. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>Focus on the solution....Not the problem.[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top