RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomListView.OnSelectItem Event

Occurs when an item is selected in the list view control.

Pascal
property OnSelectItem: TLVSelectItemEvent;
C++
__property TLVSelectItemEvent OnSelectItem;

Use OnSelectItem to perform actions when an item is selected.  

C++ Examples: 

 

/*
This code resizes the active control to twice as wide and
half as high:
*/
void __fastcall TForm1::ButtonTSClick(TObject *Sender)
{
  TRect MyRect;
  if (myActiveControl == NULL) exit;
  MyRect = myActiveControl->BoundsRect;
  MyRect.Right = MyRect.Left + (MyRect.Right - MyRect.Left) / 2;
  MyRect.Bottom = MyRect.Top + 2 * (MyRect.Bottom - MyRect.Top);
  myActiveControl->BoundsRect = MyRect;
}
void __fastcall TForm1::ButtonSFClick(TObject *Sender)
{
  TRect MyRect;
  if (myActiveControl == NULL) exit;
  MyRect = myActiveControl->BoundsRect;
  MyRect.Right = MyRect.Left + 2 * (MyRect.Right - MyRect.Left);
  MyRect.Bottom = MyRect.Top + (MyRect.Bottom - MyRect.Top) / 2;
  myActiveControl->BoundsRect = MyRect;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TComponent *Temp;
  TListItem *ListItem;
  ListView1->ViewStyle = vsList;
  ListItem = ListView1->Items->Add();
  ListItem->Caption = "Components: ";
  for (int I = ComponentCount - 1; I >= 0; I--)
  {
    Temp = Components[I];
    ListItem = ListView1->Items->Add();
    ListItem->Caption = Temp->Name;
  }
}
void __fastcall TForm1::ListView1SelectItem(TObject *Sender, TListItem *Item,
      bool Selected)
{
  TComponent *comp = FindComponent(Item->Caption);
  if (dynamic_cast<TWinControl *>(comp) != NULL)
    myActiveControl = dynamic_cast<TWinControl *>(comp);
}

 

Delphi Examples: 

{
This code resizes the active control to twice as wide and
half as high:
}
procedure TForm1.ButtonSFClick(Sender: TObject);
var
  MyRect: TRect;
begin
  if (myActiveControl = nil) then exit;
  MyRect := myActiveControl.BoundsRect;
  MyRect.Right := MyRect.Left + (MyRect.Right - MyRect.Left) * 2;
  MyRect.Bottom := MyRect.Top + (MyRect.Bottom - MyRect.Top) div 2;
  myActiveControl.BoundsRect := MyRect;
end;

procedure TForm1.ButtonTSClick(Sender: TObject);
var
  MyRect: TRect;
begin
  if (myActiveControl = nil) then exit;
  MyRect := myActiveControl.BoundsRect;
  MyRect.Right := MyRect.Left + (MyRect.Right - MyRect.Left) div 2;
  MyRect.Bottom := MyRect.Top + (MyRect.Bottom - MyRect.Top) * 2;
  myActiveControl.BoundsRect := MyRect;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
  Temp: TComponent;
  ListItem: TListItem;
begin
  ListView1.ViewStyle := vsList;
  ListItem := ListView1.Items.Add;
  ListItem.Caption := 'Components: ';
  for I := ComponentCount - 1 downto 0 do
  begin
    Temp := Components[I];
    begin
      ListItem := ListView1.Items.Add;
      ListItem.Caption := Temp.Name;
    end;
  end;
end;

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
var comp: TComponent;
begin
  comp := FindComponent(Item.Caption);
  if comp is TWinControl then
    myActiveControl := TWinControl(comp);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!