使用 IntraWeb (19) - 基本控件之 TIWTreeView    


这是个饱受非议的控件; 我通过尝试, 理解了非议, 也能理解作者. 总之向作者的思路靠拢吧, 还是不错的.



TIWTreeView 所在单元及继承链:
IWCompTreeview.TIWTreeView < TIWCustomControl < TIWBaseHTMLControl < TIWBaseControl < TIWVCLBaseControl < TControl < TComponent < TPersistent < TObject

主要成员:


property Items: TIWTreeViewItems    //所有 Item 的集合property Selected: TIWTreeViewItem  //在这里, 叫做 "当前 Item" 更合适property AutoIndent: Boolean               //是否自动缩排; 默认 Trueproperty DoServerSidePlusMinus: Boolean    //如果是 True, Html 中不包含被折叠的部分, 需要展开时再从服务器读取; 相反, Html 中包含所有节点; 默认 Falseproperty TreeViewImages: TIWTreeViewImages //通过其 OpenFolderImage、ClosedFolderImage、DocumentImage、PlusImage、MinusImage 子属性指定五个图标property ItemSpace: TIWTreeViewItemSpace //调整纵、横间距property UseItemImages: Boolean          //是否使用 Item 标志图像property TreeViewImagesWidth: Integer    //图标宽度property TreeViewImagesHeigth: Integer   //图标高度property UseFrame: Boolean               //是否使用框架property ScrollToName: string            //滚动到指定名称的 Itemproperty ScrollBars: TIWScrollStyle      //滚动条选项property WrapItems: Boolean              //Item 文本能否换行; 默认 Falseproperty DoRefreshControl: Boolean       //在修改某些属性时必须让它为 True 才会有效property TreeItemClick: TIWTreeViewClickEvent //通过它可以为每个 Item 指定 Click 事件property OnPlusMinus: TTreeViewPlusMinusProc  //每当展开或收拢子节点时procedure ClearAll  //


TIWTreeViewItems 与 TIWTreeViewItem:


{IWCompTreeview.TIWTreeViewItems < TOwnedCollection < TCollection < TPersistent < TObject}property Count: Integerproperty Items[AIndex: Integer]: TIWTreeViewItemfunction Add(aParentItem: TIWTreeViewItem): TIWTreeViewItemprocedure Clearprocedure Delete(Index: Integer)function Insert(Index: Integer): TCollectionItem{IWCompTreeview.TIWTreeViewItem < TCollectionItem < TPersistent < TObject}property ParentItem: TIWTreeViewItemproperty SubItems: TListproperty UserData: TObjectproperty Caption: stringproperty Expanded: Booleanproperty Font: TIWFontproperty Hint: stringproperty ItemImages: TIWTreeViewImagesproperty Tag: Integerproperty URL: stringproperty Version: Integerproperty Css: stringproperty Collection: TCollectionproperty ID: Integerproperty Index: Integerproperty Name: stringproperty DisplayName: stringproperty OnClick: TNotifyEventprocedure DoClickfunction HasChild: Boolean


测试:



{在空白窗体上放 IWRegion1 和 IWTreeView1; 下面代码在设计时实现会更方便}procedure TIWForm1.IWAppFormCreate(Sender: TObject);var  fItem: TIWTreeViewItem;begin  IWRegion1.Width := 200;  IWRegion1.Align := alLeft;  IWRegion1.Color := clWebYellow;  LinkColor := clWebRed; //如果给 TIWTreeViewItem 指定了 OnClick 事件, 它会被呈现为链接  IWTreeView1.Parent := IWRegion1;  IWTreeView1.Align := alClient;  IWTreeView1.Items.Add(nil).Caption := 'ItemA';  IWTreeView1.Items.Add(nil).Caption := 'ItemB';  IWTreeView1.Items.Add(nil).Caption := 'ItemC';  fItem := IWTreeView1.Items.Add(nil);  fItem.Caption := 'ItemD';    IWTreeView1.Items.Add(fItem).Caption := 'ItemD1';    IWTreeView1.Items.Add(fItem).Caption := 'ItemD2';    fItem := IWTreeView1.Items.Add(fItem);    fItem.Caption := 'ItemD3';      IWTreeView1.Items.Add(fItem).Caption := 'ItemD31';      IWTreeView1.Items.Add(fItem).Caption := 'ItemD32';end;{尽管可以为每个 Item 指定 OnClick, 但我觉得用 TreeItemClick 事件一起指定更方便; 事件中可以通过其 Tag、ID、Name、Caption等来区别}procedure TIWForm1.IWTreeView1TreeItemClick(Sender: TObject; ATreeViewItem: TIWTreeViewItem);begin  if not ATreeViewItem.HasChild then    WebApplication.ShowMessage(ATreeViewItem.Caption);end;


效果图:




©著作权归作者所有:来自51CTO博客作者JLee79的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. Delphi 正则表达式语法(10): 选项
  2. 使用 IntraWeb (20) - 基本控件之 TIWGrid
  3. pyinstaller打包总结
  4. nginx开启日志,指定格式,查看执行时间
  5. 自动化运维Saltstack
  6. rsync实现服务器数据同步备份
  7. MySQL闪回工具--MyFlash
  8. MySQL测试工具之-tpcc
  9. 【DB笔试面试462】如何将一个数字转换为字符串并且按照指定格式

随机推荐

  1. golang判断字符是不是字母
  2. 从go语言闭包谈函数式编程
  3. golang 空指针怎么检查
  4. Golang怎么判断int是否为空
  5. go语言中函数与方法介绍
  6. golang版本1哪年发明的
  7. golang1.11改了哪里东西
  8. golang数组与切片的不同之处
  9. golang怎么判断数组是否为空
  10. golang 有gc吗