We help IT Professionals succeed at work.

ListView

ntony
ntony asked
on
I what to create a component derived from TListView.
I need to create some Columns and set some properties like RowSelect and ViewStyle(vsReport).

The problem is that if i do this:

constructor TMyListView.Create(AOwner: TComponent);
begin
     inherited Create(AOwner);
     ViewStyle:=vsReport;
     RowSelect:=True;
     Columns.Add.Caption:='Name';
end;

,put a the component on a form and run the application =>
ERROR: Control has no parent windows.
Where is the problem?

PS: this is all the code (added)

Regards
NTony.
Comment
Watch Question

Senior developer
Commented:
Hi ntony,

there is really no parent window in constructor, move your initialization to SetParent method.

----
Igor.

procedure SetParent(AParent: TWinControl); override;
....
procedure  TMyListView.SetParent(AParent: TWinControl);
begin
  Inherited;
  if Parent <> nil then
    Columns.Add.Caption:='Name';
end;

Explore More ContentExplore courses, solutions, and other research materials related to this topic.