combobox的级联问题(100分)

  • 主题发起人 主题发起人 wd5i
  • 开始时间 开始时间
W

wd5i

Unregistered / Unconfirmed
GUEST, unregistred user!
数据库设计这样 <br>中东 &nbsp;沙特 <br>中东 &nbsp;科威特 <br>亚洲 &nbsp;中国 <br>亚洲 &nbsp;日本 <br>用两个combobox,第一个combobox1中可以选择的是中东和亚洲,若combobox1选中中东,则combobox2才可用并只能出现沙特、科威特 &nbsp;<br>如何实现? <br>我自己写的在combobox1中选择中东后,在combobox2中只出现一条记录,不知是什么原因?
 
用ComboBox的onchange事件<br>procedure TForm1.ComboBox1Change(Sender: TObject);<br>begin<br>&nbsp; with adq do<br>&nbsp; begin<br>&nbsp; &nbsp; Close;<br>&nbsp; &nbsp; sql.clear;<br>&nbsp; &nbsp; sql.add('查询语句');<br>&nbsp; &nbsp; Open;<br>&nbsp; &nbsp; if isempty then<br>&nbsp; &nbsp; &nbsp; showmessage('该数据为空')<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; while not eof do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ComboBox2.Items.Add(查询的数据);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 
呵呵 还不一定他能看懂呢
 
我来对上面代码进行下补充:<br>用ComboBox的onchange事件<br>procedure TForm1.ComboBox1Change(Sender: TObject);<br>begin<br>&nbsp; with adq do<br>&nbsp; begin<br>&nbsp; &nbsp; Close;<br>&nbsp; &nbsp; sql.clear;<br>&nbsp; &nbsp; sql.add('查询语句');<br>&nbsp; &nbsp; Open;<br>&nbsp; &nbsp; if isempty then<br>&nbsp; &nbsp; &nbsp; showmessage('该数据为空')<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; //--add by lngdtommy <br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ComboBox2.Items.Clear; //这需要将ComboBox2清空。。。 <br>&nbsp; &nbsp; //--end add...<br>&nbsp; &nbsp; &nbsp; while not eof do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ComboBox2.Items.Add(查询的数据);<br>&nbsp; &nbsp; &nbsp; &nbsp; Next; &nbsp;//这也需要,否则死循环。。。<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; //--add by lngdtommy<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; //--end add....<br>&nbsp; end;<br>end;
 
我说呢,原来没写next
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部