如何确定Delphi FMX中刷卡的列表视图上的哪个项目

发布于 2025-01-22 18:41:13 字数 609 浏览 0 评论 0原文

我想向左滑动&在Delphi 11.1 Alexandra中的TlistView对象中的一个项目。

我确实选择了左&来自标准手势和手势的正确手势效果很好,但我无法确定哪些项目的刷新。

procedure TTest.ListView1Gesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
        Case EventInfo.GestureID of
             sgiLeft  :
                   begin
                       ListView1.Items.Delete(ListView1.Selected.Index);
                   end;
        End;
end;

我确实尝试通过使用ListView1.selected.index来获得,但不幸的是,它并不稳定,因为有时在选择事件之前出现手势。

我还尝试使用ListView1.Itemindex,但没有机会。

如果您知道如何获得刷新的项目索引,请提供帮助。

谢谢

I would like to swipe Left & right an Item in TListView object in Delphi 11.1 Alexandra.

I did choose Left & Right gestures from the Standard gestures and gesture works fine but I cannot determine which Item exactly swiped.

procedure TTest.ListView1Gesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
        Case EventInfo.GestureID of
             sgiLeft  :
                   begin
                       ListView1.Items.Delete(ListView1.Selected.Index);
                   end;
        End;
end;

I did try to get by using ListView1.Selected.Index but unfortunately it is not stable as sometimes gestures comes before the selection event.

I also tried to use ListView1.ItemIndex but no chance.

Please help if you have any idea how to get the Swiped Item index.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻想少年梦 2025-01-29 18:41:13

感谢雷米的回答。请参阅下面的方法

procedure TForm1.ListView1Gesture(Sender: TObject;
const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
   R: TRectF;
   I: Integer;
   LStartItemIndex, LEndItemIndex : Integer;
begin    

     Case EventInfo.GestureID of
          sgiLeft  :
                    begin
                    //To find out the fist and the last item index of listview items on the screen
                    GetStartEndItemsIndex(ListView1, LStartItemIndex, LEndItemIndex);

                    //To idenfity the the item swiped to left 
                    for I := LStartItemIndex-1 to LEndItemIndex  do
                    begin
                          R := ListView1.GetItemRect(I);

                          if (R.Bottom > EventInfo.Location.Y) and (R.Top < EventInfo.Location.Y) then
                          begin
                              ListView1.Items.Delete(I); break;
                          end;
                    end;
end;

procedure TForm1.GetStartEndItemsIndex(const AListView : TListView; out AStartItemIndex : Integer; out AEndItemIndex : Integer);
var
   LViewportStart, LViewportEnd, LItemAbsEnd : Single;
   LItemIndex : Integer;
begin

   AStartItemIndex := -1;
   AEndItemIndex   := -1;

   LViewportStart := AListView.ScrollViewPos;
   LViewportEnd := AListView.Height + LViewportStart;

   for LItemIndex := 0 to AListView.Items.Count - 1 do
   begin
        LItemAbsEnd := AListView.GetItemRect(LItemIndex).Bottom + AListView.ScrollViewPos;
        if (AStartItemIndex < 0) and (LItemAbsEnd >= LViewportStart) then
        begin
           AStartItemIndex := LItemIndex;
        end;
        if (AStartItemIndex >= 0) and (AEndItemIndex < 0) and (LItemAbsEnd >= LViewportEnd) then
        begin
             AEndItemIndex := LItemIndex;
             Break;
        end;
    end;
    if (AEndItemIndex < 0) and (AListView.Items.Count > 0) then
    begin
       AEndItemIndex := AListView.Items.Count - 1;
    end;
 end;

Thanks to Remy's answer. Please see my approach as below

procedure TForm1.ListView1Gesture(Sender: TObject;
const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
   R: TRectF;
   I: Integer;
   LStartItemIndex, LEndItemIndex : Integer;
begin    

     Case EventInfo.GestureID of
          sgiLeft  :
                    begin
                    //To find out the fist and the last item index of listview items on the screen
                    GetStartEndItemsIndex(ListView1, LStartItemIndex, LEndItemIndex);

                    //To idenfity the the item swiped to left 
                    for I := LStartItemIndex-1 to LEndItemIndex  do
                    begin
                          R := ListView1.GetItemRect(I);

                          if (R.Bottom > EventInfo.Location.Y) and (R.Top < EventInfo.Location.Y) then
                          begin
                              ListView1.Items.Delete(I); break;
                          end;
                    end;
end;

procedure TForm1.GetStartEndItemsIndex(const AListView : TListView; out AStartItemIndex : Integer; out AEndItemIndex : Integer);
var
   LViewportStart, LViewportEnd, LItemAbsEnd : Single;
   LItemIndex : Integer;
begin

   AStartItemIndex := -1;
   AEndItemIndex   := -1;

   LViewportStart := AListView.ScrollViewPos;
   LViewportEnd := AListView.Height + LViewportStart;

   for LItemIndex := 0 to AListView.Items.Count - 1 do
   begin
        LItemAbsEnd := AListView.GetItemRect(LItemIndex).Bottom + AListView.ScrollViewPos;
        if (AStartItemIndex < 0) and (LItemAbsEnd >= LViewportStart) then
        begin
           AStartItemIndex := LItemIndex;
        end;
        if (AStartItemIndex >= 0) and (AEndItemIndex < 0) and (LItemAbsEnd >= LViewportEnd) then
        begin
             AEndItemIndex := LItemIndex;
             Break;
        end;
    end;
    if (AEndItemIndex < 0) and (AListView.Items.Count > 0) then
    begin
       AEndItemIndex := AListView.Items.Count - 1;
    end;
 end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文