2017-02-27 95 views
0

我有一個TListView和一個TObjectList。我將TFoo.value綁定到Item.Caption。 我寫了一個程序「AfterScroll」,裏面有一個showmessage。我連接TBindSourceAdapter.AfterScroll上的過程。Delphi:Livebindings TListView上的AfterScroll

我運行這個程序,我只有一個showmessage。

如果我用TStringGrid替換TListView,我在每行上都有showmessage。

type 
    TFoo = class 
    private 
     FValue: string; 
    public 
     constructor create(sValue: string); 
     property Value: string read FValue write FValue; 
    end; 

    TForm5 = class(TForm) 
     PrototypeBindSource1: TPrototypeBindSource; 
     StringGrid1: TStringGrid; 
     BindingsList1: TBindingsList; 
     LinkGridToDataSourcePrototypeBindSource1: TLinkGridToDataSource; 
     ListView1: TListView; 
     LinkFillControlToField1: TLinkFillControlToField; 
     procedure PrototypeBindSource1CreateAdapter(Sender: TObject; var ABindSourceAdapter: TBindSourceAdapter); 
    private 
     { Déclarations privées } 
     ListFoo: TObjectList<TFoo>; 
     procedure AfterScrool(Adapter: TBindSourceAdapter); 
    public 
     { Déclarations publiques } 
     constructor create(AOwner: TComponent); override; 
    end; 

var 
    Form5: TForm5; 

implementation 

{$R *.fmx} 
{ TForm5 } 

procedure TForm5.AfterScrool(Adapter: TBindSourceAdapter); 
begin 
    ShowMessage('kk'); 
end; 

constructor TForm5.create(AOwner: TComponent); 
begin 
    ListFoo := TObjectList<TFoo>.create(); 
    ListFoo.Add(TFoo.create('Test')); 
    ListFoo.Add(TFoo.create('Test 1')); 
    ListFoo.Add(TFoo.create('Test 2')); 
    ListFoo.Add(TFoo.create('Test 3')); 

    inherited create(AOwner); 
end; 

procedure TForm5.PrototypeBindSource1CreateAdapter(Sender: TObject; var ABindSourceAdapter: TBindSourceAdapter); 
begin 
    ABindSourceAdapter    := TListBindSourceAdapter<TFoo>.create(self, ListFoo); 
    ABindSourceAdapter.AfterScroll := AfterScrool; 
end; 

{ TFoo } 

constructor TFoo.create(sValue: string); 
begin 
    inherited create; 
    FValue := sValue; 
end; 

end. 

enter image description here

有可能在TListView的連接的 「AfterScroll」 事件?

+0

的 「同步」 屬性是這臺機子還是FMX? – MartynA

+0

它在VCL和FMX中。 – Joc02

+0

VCL TListView是標準Windows控件的封裝,所以我認爲您需要將VCL代碼添加到您的q中,以便讀者可以看到您如何嘗試這樣做以及它可能會出錯。 – MartynA

回答

0

我發現,我們需要綁定 「*」 上的TListView

enter image description here