ComboBoxEx1用这个如何实现下拉缩进关系如下(200)

  • 主题发起人 主题发起人 qq_tom1520
  • 开始时间 开始时间
顶 let_it_be
 
多加100分
 
控件直接粘贴给你看吧,你拷贝后粘贴你窗口上运行就行了,还可以设置Images属性显示图片,只是不显示树节点而已,不过这并不重要了,非要树节点那么要不换第三方控件,要不在Combobox、Edit等控件下方隐藏一个TreeView,点击时候显示出来,选中那么收起把TreeView内容显示在Edit里面就得了,以下是控件内容,把它粘贴到你窗体上:object ComboBoxEx1: TComboBoxEx Left = 248 Top = 176 Width = 145 Height = 22 ItemsEx = < item Caption = #20013#22269 Indent = 0 end item Caption = #21271#20140 Indent = 1 end item Caption = #28246#21335 Indent = 1 end item Caption = #24191#19996 Indent = 1 end item Caption = #24191#24030 Indent = 2 end item Caption = #28145#22323 Indent = 1 end item Caption = #22235#24029 Indent = 1 end item Caption = #32654#22269 Indent = 0 end item Caption = #25915#20987'1' Indent = 1 end item Caption = #25915#20987'2' Indent = 1 end item Caption = #25915#20987'3' Indent = 1 end item Caption = #25915#20987'4' Indent = 1 end> ItemHeight = 16 TabOrder = 0 DropDownCount = 8end这里是动态添加树节点的代码:procedure TForm1.Button1Click(Sender: TObject);begin //想修改树节点层次(Ident)的话只要修改倒数第二个参数即可 ComboBoxEx1.ItemsEx.AddItem('日本', -1, -1, -1, 0, nil); ComboBoxEx1.ItemsEx.AddItem('日本1', -1, -1, -1, 1, nil); ComboBoxEx1.ItemsEx.AddItem('日本2', -1, -1, -1, 1, nil);end;
 
再教你个土方法,简单实用,成本低。用Edit、TreeView、BitBtn等控件组合起来就行了,还挺好用,完全能满足你的要求,如果有兴趣的话可以改写成一个组件,用的地方不多那就没必要,这是控件代码和源码,粘贴到你窗口上就能用。控件源码:object TreeView1: TTreeView Left = 360 Top = 126 Width = 120 Height = 97 Indent = 19 TabOrder = 0 OnKeyPress = TreeView1KeyPress OnMouseDown = TreeView1MouseDown Items.Data = { 010000001D0000000000000000000000FFFFFFFFFFFFFFFF0000000005000000 04D6D0B9FA1D0000000000000000000000FFFFFFFFFFFFFFFF00000000000000 0004B1B1BEA91D0000000000000000000000FFFFFFFFFFFFFFFF000000000000 000004BAFEC4CF1D0000000000000000000000FFFFFFFFFFFFFFFF0000000002 00000004B9E3B6AB1D0000000000000000000000FFFFFFFFFFFFFFFF00000000 0000000004B9E3D6DD1D0000000000000000000000FFFFFFFFFFFFFFFF000000 000000000004C9EEDBDA1D0000000000000000000000FFFFFFFFFFFFFFFF0000 00000200000004C3C0B9FA1E0000000000000000000000FFFFFFFFFFFFFFFF00 0000000000000005B9A5BBF7311E0000000000000000000000FFFFFFFFFFFFFF FF000000000000000005B9A5BBF7321D0000000000000000000000FFFFFFFFFF FFFFFF000000000000000004C8D5B1BE}endobject Edit1: TEdit Left = 360 Top = 104 Width = 121 Height = 21 TabOrder = 1endobject BitBtn1: TBitBtn Left = 460 Top = 106 Width = 19 Height = 18 TabOrder = 2 OnClick = BitBtn1Click Glyph.Data = { DE000000424DDE00000000000000360000002800000008000000070000000100 180000000000A800000000000000000000000000000000000000D8E9ECD8E9EC D8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9EC000000D8E9 ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9EC000000000000000000D8E9ECD8E9ECD8 E9ECD8E9EC000000000000000000000000000000D8E9ECD8E9EC000000000000 000000000000000000000000000000D8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9 ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8E9ECD8 E9EC}end代码:procedure TForm1.FormCreate(Sender: TObject);begin with Edit1 do begin ReadOnly:= true; Color:= clSilver; end; with TreeView1 do begin Visible:= false; ReadOnly:= true; end;end;procedure TForm1.BitBtn1Click(Sender: TObject);begin with TreeView1 do begin Visible:= true; SetFocus; end;end;procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var AnItem: TTreeNode; HT: THitTests;begin if TreeView1.Selected = nil then Exit; HT := TreeView1.GetHitTestInfoAt(X, Y); AnItem := TreeView1.GetNodeAt(X, Y); if htOnItem in HT then begin Edit1.Text:= TreeView1.Selected.Text; TreeView1.Visible:= false; end;end;procedure TForm1.TreeView1KeyPress(Sender: TObject; var Key: Char);begin if (Key = #13) and (TreeView1.Selected <> nil) then begin Edit1.Text:= TreeView1.Selected.Text; TreeView1.Visible:= false; Key:= #0; //Eat key end;end;
 
北京男人,你的代码不实用,procedure TForm1.BitBtn1Click(Sender: TObject);begin with TreeView1 do begin Visible:= true; SetFocus; end;end;除了BitBtn1Click之外,鼠标单击其他区域,TreeView1应该hide,你的代码做不到。
 
这样的问题不用多想,用TreeView。况且楼主(后来补充的)的数据库就是为Treeview“生”的。
 
多人接受答案了。
 
let_it_be,那你说什么样的代码实用?你给写一个!有bug你可以说有bug,用词不当。
 
后退
顶部