delphi - Firemonkey ListView item indexes not updating -
i'm using tlistview in firemonkey. on startup, create 3 list view headers , keep references them future use (specifically inserting items below each header).
fitemheader:= lv.items.add; fitemheader.purpose:= tlistitempurpose.header; fitemheader.text:= 'items'; fchargeheader:= lv.items.add; fchargeheader.purpose:= tlistitempurpose.header; fchargeheader.text:= 'charges'; fpaymentheader:= lv.items.add; fpaymentheader.purpose:= tlistitempurpose.header; fpaymentheader.text:= 'payments'; then, i've added few items below first (item) header, works fine.
someitem:= lv.items.insert(fchargeheader.index); then later, wish insert item below 1 of other headers...
someitem:= lv.items.insert(fpaymentheader.index); this supposed add item above payments header (last item in charges section). however, instead gets added further list (at index 2).
while debugging issue, came surprise 3 headers' indexes have not been updated after adding items. following code demonstrated that:
s:= 'items: '+inttostr(fitemheader.index)+slinebreak+ 'charges: '+inttostr(fchargeheader.index)+slinebreak+ 'payments: '+inttostr(fpaymentheader.index); showmessage(s); the indexes 0, 1, , 2 though they're supposed larger (after adding items).
further debugging led me add code:
for x := 0 lv.items.count-1 begin s:= s + lv.items[x].text+' - '+inttostr(lv.items[x].index)+slinebreak; end; showmessage(s); which reports correct indexes. further, if call second piece of code , first piece, indexes fine..
for x := 0 lv.items.count-1 begin s:= s + lv.items[x].text+' - '+inttostr(lv.items[x].index)+slinebreak; end; showmessage(s); s:= 'items: '+inttostr(fitemheader.index)+slinebreak+ 'charges: '+inttostr(fchargeheader.index)+slinebreak+ 'payments: '+inttostr(fpaymentheader.index); showmessage(s); so after bit more digging, turns out simple call to...
lv.items[1].index; ...forced particular item re-indexed.
while technically works, it's extremely sloppy work-around. else can ensure list view gets re-indexed prior inserting item?
note: when did similar approach using tlistbox did not have issue. it's surely bug in tlistview control. i'm not asking how fix bug, better work-around.
note: work-around appeared work once or twice - further attempts , work-around doesn't force re-index.
update
it seems magical work-around, still sloppy:
procedure reindexlistview(alistview: tlistview); var x: integer; begin x := 0 alistview.items.count-1 alistview.items[x].index; end;
this bug in delphi xe8. works fine in delphi xe7 update 1.
read more bug: delphi xe8 bug in tlist<t>, need workaround
really looks bug. tested delphi xe8 under win32 , win64.
method .additem has same effect .insert
how looks:

how should (and how looks if using lv.items[1].index). note: same effect if prior adding item under "charges" going select item in tlistview

Comments
Post a Comment