Board index » delphi » Q: TListBox.ItemIndex changes to -1 when accessing .Items

Q: TListBox.ItemIndex changes to -1 when accessing .Items

I don't understand this one.  Can anyone help?

Quite simply I have a master list and need to update my listbox with the
change.  The code:

 LayoutLB.Items[CurrentLayoutIndex] := LayoutList[CurrentLayoutIndex];

Once this line executes the ListBox, LayoutLB.ItemIndex changes to (-1).
It was valid before this line.  I know I could update the entire list, but
I don't know if that will work, I'm gonna try it now, but I also really
don't want to update needlessly.  Only 1 line needs changing at a time.  ;)

Why?

Any ideas?

Many thanks in advance,

-- Jim Burns
   Consultant      Technology Dynamics
                     Pearland, Texas
                       (713) 485-0410
                         jimbu...@technologydynamics.com

 

Re:Q: TListBox.ItemIndex changes to -1 when accessing .Items


Quote
In article <55tbdd$...@ganja.nol.net> jimbu...@technologydynamics.com (Jim Burns) writes:
>From: jimbu...@technologydynamics.com (Jim Burns)
>Subject: Q:  TListBox.ItemIndex changes to -1 when accessing .Items
>Date: Thu, 07 Nov 1996 18:56:59 GMT
>I don't understand this one.  Can anyone help?
>Quite simply I have a master list and need to update my listbox with the
>change.  The code:
> LayoutLB.Items[CurrentLayoutIndex] := LayoutList[CurrentLayoutIndex];
>Once this line executes the ListBox, LayoutLB.ItemIndex changes to (-1).
>It was valid before this line.  I know I could update the entire list, but
>I don't know if that will work, I'm gonna try it now, but I also really
>don't want to update needlessly.  Only 1 line needs changing at a time.  ;)
>Why?
>Any ideas?

adding new items seems to invalidate the itemindex - perhaps you could stash
itemindex in a var prior to adding items, then set it back from the var
afterwards

HTH

Boris Ingram, Cyborg Software
boris...@iafrica.com
100076.3...@compuserve.com
http://www.pcb.co.za/users/borising/cyborg.htm

Other Threads