Reputation: 6837
I've been playing around with TListView and have been trying to work out how WorkAreas work, and what they are useful for. There seems to be very little documentation (big surprise) on it.
Has anyone successfully used WorkAreas? If so what for?
I have been trying things like the following:
wa := ListView1.WorkAreas.Add;
wa.DisplayName := 'Work Area 0';
wa.Rect.Width := ListView1.Width div 2;
wa.Rect.Height := ListView1.Height;
which seems to create a work area region, and you can determine if an item is associated with that work area by checking its WorkArea property.
Upvotes: 5
Views: 828
Reputation: 54822
It is the VCL's support for the native List-View control's Working Areas. See List-View Working Areas. The documentation gives an example for what they can be used for:
[...] Multiple working areas can be used for creating different areas within one view. You can create areas in a single view that have different meanings. For example, a view of a file system might have an area for read/write files and another area for read-only files. The user can categorize items by placing them in different working areas. [...]
The documentation also mentions that you can create empty borders near edges or cause scroll bars where normally none would be by using work areas.
There doesn't seem to be much missing from VCL's documentation. You can add and query work areas. Relocate an item to a particular work area, or ask it in what work area it lives. Nothing is automatic, all you have to do it yourself. An item is not associated with a work area, you have to move it yourself (VCL just iterates over work areas and checks coordinates of the item and the area to find the work area an item is in).
The categorization part is not probably extremely useful, as one can keep his/her own virtual regions without the help of the control itself. The bits about edges and scroll bars are probably more important. But I've never seen such thing implemented in an application, including the OS itself.
type
TForm1 = class(TForm)
Button1: TButton;
ListView1: TListView;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
uses
commctrl;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
R1, R2: TRect;
begin
R1 := Rect(0, 0,
ListView1.ClientWidth div 2, ListView1.ClientHeight div 2 + 10);
R2 := Rect(ListView1.ClientWidth div 2 + 1, 0,
ListView1.ClientWidth - 1, ListView1.ClientHeight div 2 + 10);
ListView1.WorkAreas.Add.Rect := R1;
ListView1.WorkAreas.Add.Rect := R2;
ListView1.AddItem('Item 1', nil);
ListView1.AddItem('Item 2', nil);
ListView1.AddItem('Item 3', nil);
ListView1.AddItem('Item 4', nil);
ListView1.AddItem('Item 5', nil);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ListView1.Items.Count - 1 do begin
ListView1.Items[i].Left := ListView1.WorkAreas[1].Rect.Left;
ListView1.Items[i].Top := ListView1.WorkAreas[1].Rect.Top;
end;
ListView1.Arrange(arAlignTop);
end;
Initial view:
After pressing the button:
Note that in the first picture "Item 5" is not in any work area. In the button click handler I tried to put all of the five items in the 'right-top' work area. After "Item 5" is put there, the control has decided to kick out "Item-1" since all five did not fit. It should be evident by now that I've never used work areas, but I purposefully gave this example to be able to point possible quirks. What I expected was that a scrollbar to appear as mentioned in the documents.
Upvotes: 6