View Issue Details

IDProjectCategoryView StatusLast Update
0035957LazarusWidgetsetpublic2019-08-14 03:51
ReporterLazProggerAssigned ToDmitry Boyarintsev 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformOSmacOSOS Version
Product Version2.0.4Product Build 
Target VersionFixed in Version 
Summary0035957: Cocoa: ListView with OwnerData not showing rows when added at run-time
DescriptionWhen 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 ReproduceAn 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.
TagsNo tags attached.
Fixed in Revision61687
LazTarget-
WidgetsetCocoa
Attached Files

Relationships

has duplicate 0035961 closedDmitry Boyarintsev (Cocoa) TListView.SetCount does not update the GUI 

Activities

LazProgger

2019-08-12 14:39

reporter  

MacTestVirtualListView.zip (6,702 bytes)

Dmitry Boyarintsev

2019-08-12 16:50

developer   ~0117656

please test and close if ok

LazProgger

2019-08-12 18:05

reporter   ~0117657

thank you very much! the sample project is working now.

Issue History

Date Modified Username Field Change
2019-08-12 14:39 LazProgger New Issue
2019-08-12 14:39 LazProgger File Added: MacTestVirtualListView.zip
2019-08-12 16:50 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2019-08-12 16:50 Dmitry Boyarintsev Status new => resolved
2019-08-12 16:50 Dmitry Boyarintsev Resolution open => fixed
2019-08-12 16:50 Dmitry Boyarintsev Fixed in Revision => 61687
2019-08-12 16:50 Dmitry Boyarintsev LazTarget => -
2019-08-12 16:50 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2019-08-12 16:50 Dmitry Boyarintsev Note Added: 0117656
2019-08-12 18:05 LazProgger Note Added: 0117657
2019-08-12 20:17 LazProgger Status resolved => closed
2019-08-14 03:51 Dmitry Boyarintsev Relationship added has duplicate 0035961