在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
TScrollBox -> TCustomTreeView -> TTreeView 子项类型是 TTreeViewItem. 测试, 先在窗体上放一个 TTreeView, 并需要它的 OnChange 事件: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Layouts, FMX.TreeView; type TForm1 = class(TForm) TreeView1: TTreeView; procedure FormCreate(Sender: TObject); procedure TreeView1Change(Sender: TObject); end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.FormCreate(Sender: TObject); var item: TTreeViewItem; i: Integer; begin TreeView1.Align := TAlignLayout.alLeft; TreeView1.UseSmallScrollBars := True; TreeView1.AlternatingRowBackground := True; TreeView1.ShowCheckboxes := True; item := TTreeViewItem.Create(Self); item.Parent := TreeView1; item.Text := 'Item1'; item := TTreeViewItem.Create(Self); item.Parent := TreeView1; item.Text := 'Item2'; for i := 0 to 19 do with TTreeViewItem.Create(Self) do begin Parent := item; Text := item.Text + '_' + IntToStr(i+1); IsChecked := Odd(i); end; item.IsExpanded := True; item := TTreeViewItem.Create(Self); item.Parent := TreeView1; item.Text := 'Item3'; end; procedure TForm1.TreeView1Change(Sender: TObject); var item: TTreeViewItem; begin item := TreeView1.Selected; if item <> nil then begin ShowMessageFmt( 'TreeView1.GlobalCount: %d'#13#10 + 'TreeView1.Count: %d'#13#10 + 'TTreeViewItem.Count: %d'#13#10 + 'TTreeViewItem.Level: %d'#13#10 + 'TTreeViewItem.GlobalIndex: %d'#13#10 + 'TTreeViewItem.Index: %d'#13#10 , [TreeView1.GlobalCount, TreeView1.Count, item.Count, item.Level, item.GlobalIndex, item.Index] ); end; end; end. 成员概览: { TCustomTreeView } public constructor Create(...); override; // destructor Destroy; override; // procedure EndUpdate; override; //结束更新 procedure Clear; //清空 procedure ExpandAll; //全部展开 procedure CollapseAll; //全部关闭 function ItemByText(...): TTreeViewItem; //根据标题获取项 function ItemByPoint(...): TTreeViewItem; //根据位置获取项 function ItemByIndex(...): TTreeViewItem; //根据索引获取项 function ItemByGlobalIndex(...): TTreeViewItem; //根据总索引获取项 procedure AddObject(...); override; // procedure RemoveObject(...); override; // procedure MouseDown(...); override; // procedure MouseMove(...); override; // procedure MouseUp(...); override; // procedure KeyDown(...); override; // procedure KeyUp(...); override; // procedure DragOver(...); override; // procedure DragDrop(...); override; // property Count: Integer ...; //第一层项总数 property GlobalCount: Integer ...; //项总数 property CountExpanded: Integer ...; //??? property Selected: TTreeViewItem ...; //当前选择的项 property Items[Index: Integer]: TTreeViewItem ...; //索引到项 property AllowDrag: Boolean ...; //是否允许拖拽 property AlternatingRowBackground: Boolean ...; //是否使用交替背景 property ItemHeight: Single ...; //项高 property HideSelectionUnfocused: Boolean ...; //是否在失去焦点时隐藏选择 property MultiSelect: Boolean ...; //能否多选 property ShowCheckboxes: Boolean ...; //是否显示多选框 property Sorted: Boolean ...; // property OnChange: TNotifyEvent ...; // property OnChangeCheck: TNotifyEvent ...; // property OnCompare: TOnCompareTreeViewItemEvent ...; // property OnDragChange: TOnTreeViewDragChange ...; // end; { TTreeView } published property StyleLookup; // property CanFocus default True; // property DisableFocusEffect; // property TabOrder; // property AllowDrag default False; // property AlternatingRowBackground default False; // property ItemHeight; // property HideSelectionUnfocused default False; // property MultiSelect default False; // property ShowCheckboxes default False; // property Sorted default False; // property OnChange; // property OnChangeCheck; // property OnCompare; // property OnDragChange; // end; { TTreeViewItem } public constructor Create(...); override; // procedure Paint; override; // procedure AddObject(...); override; // procedure RemoveObject(...); override; // procedure Sort(...); override; // function ItemByPoint(...): TTreeViewItem; //根据位置获取项 function ItemByIndex(...): TTreeViewItem; //根据索引获取项 property Count: Integer ...; //子项数 property GlobalIndex: Integer ...; //全局索引 function TreeView: TCustomTreeView; //拥有它的 TreeView function Level: Integer; //在第几层 function ParentItem: TTreeViewItem; //父项 property Items[Index: Integer]: TTreeViewItem ...; //索引到子项 published property IsChecked: Boolean ...; //是否选中复选框 property IsExpanded: Boolean ...; //是否展开 property IsSelected: Boolean ...; //是否选择 property AutoTranslate default True; //是否自动接收语言翻译 property Font; // property StyleLookup; // property Text; // property TextAlign default TTextAlign.taLeading; // end; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论