Cocoa: ListView with OwnerData not showing rows when added at run-time
Original Reporter info from Mantis: LazProgger
-
Reporter name:
Original Reporter info from Mantis: LazProgger
- Reporter name:
Description:
When having a ListView with OwnerData = true and an OnData procedure on Cocoa, the data is only showing when setting Items.Count in the OnCreate procedure of the program, not when trying to add new items with setting Items.Count during run-time.
Steps to reproduce:
An example project is attached, here is the code of the main form:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
lv_def: TListView;
lv_virtual: TListView;
bt_add_item_lv_def: TButton;
bt_add_item_lv_virtual: TButton;
procedure FormCreate(Sender: TObject);
procedure lv_virtualData(Sender: TObject; Item: TListItem);
procedure bt_add_item_lv_defClick(Sender: TObject);
procedure bt_add_item_lv_virtualClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
procedure AddItemDef;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
// set items for default listview - works on Cocoa [items are displayed when starting the program]
self.AddItemDef;
self.AddItemDef;
self.AddItemDef;
// set items for virtual listview - works on Cocoa [items are displayed when starting the program]
lv_virtual.Items.Count := 3;
end;
procedure TForm1.bt_add_item_lv_defClick(Sender: TObject);
begin
// add item to default listview - works on Cocoa [items are displayed after clicking the button]
self.AddItemDef;
end;
procedure TForm1.bt_add_item_lv_virtualClick(Sender: TObject);
begin
// add item to virtual listview - NOT WORKING on Cocoa [new items are not displayed after clicking the button]
lv_virtual.Items.Count := lv_virtual.Items.Count + 1;
self.Caption := IntToStr(lv_virtual.Items.Count); // shows the correct item count
//lv_virtual.Invalidate; - no effect
//lv_virtual.Refresh; - no effect
//lv_virtual.Repaint; - no effect
//lv_virtual.Update; - no effect
end;
procedure TForm1.lv_virtualData(Sender: TObject; Item: TListItem);
begin
// fetch virtual listview data
Item.Caption := 'Cap'+inttostr(item.Index);
Item.SubItems.Add('Sub1');
Item.SubItems.Add('Sub2');
end;
procedure TForm1.AddItemDef;
var
AItem: TListItem;
begin
// add item to default listview - works on Cocoa
AItem := lv_def.Items.Add;
AItem.Caption := 'Cap'+inttostr(lv_def.Items.Count);
AItem.SubItems.Add('Sub1');
AItem.SubItems.Add('Sub2');
end;
end.
At startup, the ListView has 3 columns, at run-time, you can add new items with the Add-button.
On Cocoa, the rows added at startup are displayed. The rows added during run-time are not displayed.
On Windows, both situations are working using the same code.
Mantis conversion info:
- Mantis ID: 35957
- OS: macOS
- Version: 2.0.4
- Fixed in revision: 61687 (#2a64470b)