• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphi学习treeview中从表列名和数据添加为目录并双击自动选中

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 


1
unit Unit2; 2 3 interface 4 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.Grids, 8 Vcl.DBGrids, Vcl.ComCtrls, Vcl.StdCtrls; 9 10 type 11 TForm2 = class(TForm) 12 TreeView1: TTreeView; 13 DBGrid1: TDBGrid; 14 ADOConnection1: TADOConnection; 15 ADOQuery1: TADOQuery; 16 DataSource1: TDataSource; 17 procedure FormShow(Sender: TObject); 18 procedure TreeView1DblClick(Sender: TObject); 19 private 20 { Private declarations } 21 public 22 { Public declarations } 23 end; 24 25 var 26 Form2: TForm2; 27 28 implementation 29 30 {$R *.dfm} 31 32 procedure TForm2.FormShow(Sender: TObject); 33 var 34 I: Integer; 35 node: TTreeNode; 36 MyFuAdq,MyZiAdq: TADOQuery; 37 begin 38 MyFuAdq := TADOQuery.Create(nil); 39 MyZiAdq := TADOQuery.Create(nil); 40 try 41 MyFuAdq.Connection := ADOConnection1; 42 MyZiAdq.Connection := ADOConnection1; 43 with MyFuAdq do 44 begin 45 SQL.Text := 'SELECT TOP 1 * FROM top_order'; 46 Open; 47 end; 48 49 for I := 0 to MyFuAdq.FieldDefs.Count - 1 do 50 begin 51 node := TreeView1.Items.Add(nil, MyFuAdq.FieldDefs[I].Name); {字段名} 52 53 //再次查询每列不同的数据 54 with MyZiAdq do 55 begin 56 Close; 57 SQL.Text := 'SELECT DISTINCT '+MyFuAdq.FieldDefs[I].Name+ ' FROM top_order'; 58 Open; 59 end; 60 while not MyZiAdq.Eof do 61 begin 62 TreeView1.Items.AddChild(node, MyZiAdq.FieldByName(MyFuAdq.FieldDefs[I].Name).AsString); 63 MyZiAdq.Next; 64 end; 65 end; 66 67 68 finally 69 MyFuAdq.Free; 70 MyZiAdq.Free; 71 end; 72 73 end; 74 75 procedure TForm2.TreeView1DblClick(Sender: TObject); 76 var 77 MyAdq: TADOQuery; 78 selectName,selectValue: string; 79 begin 80 MyAdq := TADOQuery.Create(nil); 81 try 82 MyAdq.Connection := ADOConnection1; 83 84 //获取选中的内容 85 selectName := TreeView1.Selected.Parent.Text; 86 selectValue := TreeView1.Selected.Text; 87 88 //选中 89 with MyAdq do 90 begin 91 SQL.Text := 'UPDATE top_trade SET top_xuanzhong = 1 WHERE top_xuhao IN (SELECT DISTINCT top_xuhao FROM top_order WHERE '+selectName+' = '+selectValue.QuotedString+')'; 92 ExecSQL; 93 end; 94 95 96 //查询 97 with ADOQuery1 do 98 begin 99 Close; 100 SQL.Text := 'SELECT top_order.top_title,top_trade.top_xuhao,top_trade.top_xuanzhong FROM top_order FULL JOIN top_trade ON top_order.top_xuhao = top_trade.top_xuhao WHERE top_order.'+selectName+' = '+selectValue.QuotedString; 101 Open; 102 end; 103 finally 104 MyAdq.Free; 105 end; 106 end; 107 108 end.

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab 数组操作作业发布时间:2022-07-18
下一篇:
《应用计算方法教程》matlab作业一发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap