先选用 query查找出与前两个下拉框对应的第三个下拉框的值, 然后从0到items.count-1循环 for i:=0 to combobox1.items.count-1 begin if query1.fidldbyname('字段名')=Items[i]='b' then combobox1.ItemIndex:=i; else query1.next; end;
你要有个表,比如出货表 T_Stock,至少有一下字段 货号 SNo,日期SDate,买主 Buyercombobox1的Change事件中 AdoQuery1.Close; AdoQuery1.Clear; Adoquery1.Sql.Text:='Select * from T_Stock where SNo='''+ComboBox1.Text+''''; Adoquery1.Open; ComboBox3.Text:=AdoQuery1.FieldByName('Buyer').AsString;同理在combobox2的Change事件中 AdoQuery1.Close; AdoQuery1.Clear; Adoquery1.Sql.Text:='Select * from T_Stock where SDate='''+ComboBox2.Text+''''; Adoquery1.Open; ComboBox3.Text:=AdoQuery1.FieldByName('Buyer').AsString; //这里的SDate要是字符型,如果是日期型,那要加个StrToDate之类的函数
接着上面的,我重新看了你的需求。 可能要改一下,上面那段只能分别点击ComboBox1或者ComboBox2,ComboBox3才能显值。但你是要两项合并查询。所以要改一下。combobox2的Change事件中 AdoQuery1.Close; AdoQuery1.Clear; Adoquery1.Sql.Add('Select * from T_Stock where Buyer<>''); If ComboBox1.text<>'' then Adoquery1.Sql.Add(' and SNo='''+ComBoBox1.Text+''''); if ComboBox2.Text<'' then Adoquery1.Sql.Add(' and SDate='''+ComBoBox2.Text+''''); Adoquery1.Open; ComboBox3.Text:=AdoQuery1.FieldByName('Buyer').AsString;
不好意思,打错了:) 先选用 query查找出与前两个下拉框对应的第三个下拉框的值, 然后从0到items.count-1循环 for i:=0 to combobox1.items.count-1 begin if query1.fidldbyname('字段名').Items[i]='b' then combobox1.ItemIndex:=i; else query1.next; end;
修改 combobox1的Change事件中 AdoQuery1.Close; AdoQuery1.Clear; Adoquery1.Sql.Text:='Select * from T_Stock where SNo='''+ComboBox1.Text+''''; Adoquery1.Open; combobox3.clear; while not adoquery1.eof do begin combobox3.items.add(AdoQuery1.FieldByName('Buyer').AsString); adoquery1.next; end;
然后从0到items.count-1循环
for i:=0 to combobox1.items.count-1
begin
if query1.fidldbyname('字段名')=Items[i]='b' then
combobox1.ItemIndex:=i;
else
query1.next;
end;
AdoQuery1.Close;
AdoQuery1.Clear;
Adoquery1.Sql.Text:='Select * from T_Stock where SNo='''+ComboBox1.Text+'''';
Adoquery1.Open;
ComboBox3.Text:=AdoQuery1.FieldByName('Buyer').AsString;同理在combobox2的Change事件中
AdoQuery1.Close;
AdoQuery1.Clear;
Adoquery1.Sql.Text:='Select * from T_Stock where SDate='''+ComboBox2.Text+'''';
Adoquery1.Open;
ComboBox3.Text:=AdoQuery1.FieldByName('Buyer').AsString;
//这里的SDate要是字符型,如果是日期型,那要加个StrToDate之类的函数
可能要改一下,上面那段只能分别点击ComboBox1或者ComboBox2,ComboBox3才能显值。但你是要两项合并查询。所以要改一下。combobox2的Change事件中
AdoQuery1.Close;
AdoQuery1.Clear;
Adoquery1.Sql.Add('Select * from T_Stock where Buyer<>'');
If ComboBox1.text<>'' then
Adoquery1.Sql.Add(' and SNo='''+ComBoBox1.Text+'''');
if ComboBox2.Text<'' then
Adoquery1.Sql.Add(' and SDate='''+ComBoBox2.Text+'''');
Adoquery1.Open;
ComboBox3.Text:=AdoQuery1.FieldByName('Buyer').AsString;
先选用 query查找出与前两个下拉框对应的第三个下拉框的值,
然后从0到items.count-1循环
for i:=0 to combobox1.items.count-1
begin
if query1.fidldbyname('字段名').Items[i]='b' then
combobox1.ItemIndex:=i;
else
query1.next;
end;
2.在他们的onselect事件中为第三个combobox添加相应的项
combobox1的Change事件中
AdoQuery1.Close;
AdoQuery1.Clear;
Adoquery1.Sql.Text:='Select * from T_Stock where SNo='''+ComboBox1.Text+'''';
Adoquery1.Open;
combobox3.clear;
while not adoquery1.eof do
begin
combobox3.items.add(AdoQuery1.FieldByName('Buyer').AsString);
adoquery1.next;
end;