2017-07-04 32 views
1

Toggle Design mode in FMX Listview give you thisTListView的FMX onclick事件連同切換設計

實現如下:

ds.first; 
    while not(ds.Eof) do 
    begin 
     L := LV1.Items.Add; 
     L.Data['Part_No'] := ds.FieldByName('Part_no').AsString; 
     L.Data['Part_Name'] := ds.FieldByName('Part_name').AsString; 
     L.Data['LocNo']  := ds.FieldByName('Loc_No').AsString; 
     L.Data['Qty']  := ds.FieldByName('BAL').AsFloat; 
     ds.Next; 
    end; 

我添加動態使用代碼

如何OnItemClick事件火災檢測哪些因素是項目點擊。非常沮喪地發現簡單的事情。

任何幫助表示讚賞。

+0

'AItem'是單擊的項目對象。或者你想要什麼?也許我只是誤解了.. – Victoria

回答

1

有點拼湊而成,但它應該有你開始:

function GetClickedDrawable(const AItem: TListViewItem; APoint: TPointF): TListItemDrawable; 
var 
    I: Integer; 
begin 
    Result := nil; 
    // Fudge for statusbar height if using iOS. Should be done properly 
    APoint := PointF(APoint.X, APoint.Y - 20); 
    for I := 0 to AItem.Objects.ViewList.Count - 1 do 
    begin 
    if AItem.Objects.ViewList[I].InLocalRect(APoint) then 
    begin 
     Result := AItem.Objects.ViewList[I]; 
     Break; 
    end; 
    end; 
end; 

procedure TForm1.ListViewItemClick(const Sender: TObject; const AItem: TListViewItem); 
var 
    LDrawable: TListItemDrawable; 
begin 
    LDrawable := GetClickedDrawable(AItem, ListView.AbsoluteToLocal(Screen.MousePos)); 
    if LDrawable <> nil then 
    ShowMessage(LDrawable.Name); 
end; 

你需要調整GetClickedDrawable,以滿足你在任何平臺上。 PS:謝謝你的提問;我將要做的事情非常喜歡這一點,最終:-)

編輯:

我已經離開了我原來的答覆到位的情況下,下面是不是在早期版本的可用德爾福:

使用OnItemClickEx事件。該事件的參數使其非常自我解釋

不知道爲什麼我以前沒有看到:-)