TCustomListView AV List out of bounds
Original Reporter info from Mantis: zeljko@holobit.net @zeljan1
-
Reporter name: Zeljan Rikalo
Original Reporter info from Mantis: zeljko@holobit.net @zeljan1
- Reporter name: Zeljan Rikalo
Description:
This is case Assign OnKeyDown() for TListView. add code like:
if Key = VK_DELETE then
begin
Item := TListView(Sender).Selected;
if Item <> nil then
begin
i := Item.Index;
// writeln('TForm2.ListView1KeyDown try to delete i=',i,' COUNT=',TListView(Sender).Items.Count);
TListView(Sender).Items.Delete(i);
end;
end;
Add to the list just 3 items.
Select 2nd one, press delete, press delete again and now press delete on last item -> BANG !
if we delete items like 3->2->1 or reversed 1->2->3 then everything looks nice.
So killing combination is 2->1->1.
This code below is workaround which should be added into TQtWSComCtrls into TQtWSCustomListView.ItemDelete() and after QTreeWidget_takeTopLevelItem(TW, AIndex); Of course we have to declare QtItem: QTreeWidgetItemH; Item: TListItem; ############ CODE ######### QtItem := QTreeWidget_currentItem(TW);
if QtItem <> nil then
begin
Item := ALV.Selected;
if Assigned(Item) then
begin
if Item.Index <> QTreeWidget_indexOfTopLevelItem(TW, QtItem) then
TListView(ALV).Items[QTreeWidget_indexOfTopLevelItem(TW, QtItem)].Selected := True;
end;
end;
########## END CODE ##########
It's possible that this is Qt bug, not widget set implementation, since Signals are fired while removing item, not after that, so current index is not moved to right pos.
Mantis conversion info:
- Mantis ID: 9746
- Version: 0.9.23 (SVN)