我做了个查询窗体,
查询的条件比较多:州地市,单位,税务机关,税管员,税种,行业,行业明细
这些条件都是用下拉组合框(combobox)来显示的。
比如:
我在州地市里选“四川省成都市”,后面的单位组合框就只能显示“成都市的单位”
我该怎么操作了?
谢谢!
高手们,帮忙啊!
谢谢!!!!!!!!

解决方案 »

  1.   

    combobox的onchange事件中
    把combobox的文本值設置成相應的查詢條件.
      

  2.   

    当然是在州市的combobox的onchange里写了
      

  3.   

    我试了
    但是没有实现我在form2.onshow事件中写了
    combobox提取数据库数据并显示的代码。这样对combobox的onchange的事件有影响吗?
      

  4.   

    我认为你的思路有问题:这是一个主表和子表的关系;
    应该用combobox(加载主表的内容)和dbgrid(用于显示子表的内容),
    在combobox的onchange中来写sql语句动态查询子表内容,这样应该简单一些.
      

  5.   

    我的意思是:如果"州地市"combobox中没有选择(为空),那么"单位"combobox中就应该显示的是数据库中的"全部单位"
    所以我就在form2.onshow事件中写了combobox提取数据库数据并显示的代码
    现在的问题是我在combobox的onchange中写了代码,不改变(选择了"州地市",而单位combobox中显示的仍然是全部的单位,没有将所选择的"州地市"的单位).
    不知道是不是form2.onshow已经确定了combobox显示的内容,不能在改变了吗?谢谢!!
      

  6.   

    顺便问下这个SQL语句对吗?
    s1:=copy(combobox1.Text,1,pos('[',combobox1.text)-1);//提取combobox1中的数字
    select city_num,city_name from dsbm.bmcity where city_num like '+s1+'
    谢谢!!
      

  7.   

    combobox的onchange事件中,州城市改变后,要相应改变其它的combobox的内容
      

  8.   

    我就是在combobox的onchange事件中操作的,但是就改变不了啊
    我在combobox1的onchange事件中写的 是改变combobox2内容的代码
    但是就是实现不了,显示的还是全部的内容.
    不知道是什么原因.谢谢!!
      

  9.   

    顺便问下这个SQL语句对吗? 
    s1:=copy(combobox1.Text,1,pos('[',combobox1.text)-1);//提取combobox1中的数字 
    select   city_num,city_name   from   dsbm.bmcity   where   city_num   like   '+s1+' 
    谢谢!! ________________________________________________-s1:=Trim(combobox1.text);
    Select City_num,City_name From Dsbm.bmcity Where City_num like +QuotedStr('%'+s1+'%');
      

  10.   

    s1:=Trim(combobox1.text); 
    只是去掉里面的空格,我combobox1.text中有数字和汉字(如:001[扩大解放后]),
    现在我只是提取001即可.麻烦在帮我看下,
    我的意思是:如果"州地市"combobox中没有选择(为空),那么"单位"combobox中就应该显示的是数据库中的"全部单位" 
    所以我就在form2.onshow事件中写了combobox提取数据库数据并显示的代码 
    现在的问题是我在combobox的onchange中写了代码,不改变(选择了"州地市",而单位combobox中显示的仍然是全部的单位,没有将所选择的"州地市"的单位). 
    不知道是不是form2.onshow已经确定了combobox显示的内容,不能在改变了吗? 谢谢!! 
      

  11.   

    麻烦看下我的代码:
    form.show事件代码:
    procedure TForm2.FormShow(Sender: TObject);
    var s1,s2,s3,s4,s5,s6,s7:string;
    begin
    s1:=copy(combobox1.Text,1,pos('[',combobox1.Text)-1);//州地市
    s2:=copy(combobox2.Text,1,pos('[',combobox2.Text)-1);//单位
    s3:=copy(combobox3.Text,1,pos('[',combobox3.Text)-1);//税务机关
    s4:=copy(combobox4.Text,1,pos('[',combobox4.Text)-1);//税管员
    s5:=copy(combobox5.Text,1,pos('[',combobox5.Text)-1); //行业
    s6:=copy(combobox6.Text,1,pos('[',combobox6.Text)-1); //注册类型
    s7:=copy(combobox7.Text,1,pos('[',combobox7.Text)-1); //行业明细
    //州地市LJClientDataSet2.Close;
    LJClientDataSet2.Provider.DataRequest('select zds_code ,zds_name from dsbm.bmzds order by zds_code /');
    LJClientDataSet2.Open;
    while not LJClientDataSet2.Eof do
    begin
    combobox1.Items.Add(LJClientDataSet2.fieldbyname('zds_code').asstring+'['+LJClientDataSet2.fieldByName('zds_name').asstring+']');
    LJClientDataSet2.Next;
    end;
    //单位
    LJClientDataSet5.Close;
     LJClientDataSet5.Provider.DataRequest(
     'select city_num,short_name from dsbm.bmcity '+
     ' /');
     LJClientDataSet5.Open;
     while not LJClientDataSet5.Eof do
     begin
     combobox2.Items.Add(LJClientDataSet5.fieldByName('city_num').asstring+'['+LJClientDataSet5.fieldbyname('short_name').asstring+']');
     LJClientDataSet5.Next;
     end;//税务机关LJClientDataSet3.Close;
    LJClientDataSet3.Provider.DataRequest('select  jg_code,jg_name from dsbm.swjg '+
    ' order by jg_code /');
    LJClientDataSet3.Open;
    while not LJClientDataSet3.Eof do
    begin
    combobox3.Items.Add(LJClientDataSet3.fieldbyname('jg_code').asstring+'['+LJClientDataSet3.fieldbyname('jg_name').asstring+']');
    //combobox3.Items.Add(LJClientDataSet3.fieldbyname('jg_name').asstring);
    LJClientDataSet3.Next;
    end;
    //税管员  LJClientDataSet8.Close;
      LJClientDataSet8.Provider.DataRequest('select oper_num,oper_name from dsbm.oper_def where cxjc=5 order by oper_num /');
      LJClientDataSet8.Open;
      while not LJClientDataSet8.Eof do
      begin
      combobox4.Items.Add(LJClientDataSet8.fieldbyname('oper_num').asstring+'['+LJClientDataSet8.fieldbyname('oper_name').asstring+']');
      LJClientDataSet8.Next;
      end;// 行业
     LJClientDataSet4.Close;
     LJClientDataSet4.Provider.DataRequest('select hy_old,hy_name from dsbm.bmhy /');
     LJClientDataSet4.Open;
     while not LJClientDataSet4.Eof do
     begin
     combobox5.Items.Add(LJClientDataSet4.fieldbyname('hy_old').asstring+'['+LJClientDataSet4.fieldbyname('hy_name').asstring+']');
     LJClientDataSet4.Next;
     end;
     //注册类型
     LJClientDataSet7.Close;
     LJClientDataSet7.Provider.DataRequest('select jj,jj_name from dsbm.bmjj /');
     LJClientDataSet7.Open;
     while not LJClientDataSet7.Eof do
     begin
     combobox6.Items.Add(LJClientDataSet7.fieldbyname('jj').asstring+'['+LJClientDataSet7.fieldbyName('jj_name').asstring+']');
     LJClientDataSet7.Next;
     end; //行业明细
     LJClientDataSet6.Close;
     LJClientDataSet6.Provider.DataRequest('select bm,bmnr from dsbm.bmhyxm order by bm /');
     LJClientDataSet6.Open;
     while not LJClientDataSet6.Eof do
     begin
     combobox7.Items.Add(LJClientDataSet6.fieldbyname('bm').asstring+'['+LJClientDataSet6.fieldbyname('bmnr').asstring+']');
     LJClientDataSet6.Next;
     end; end;combobox.change事件代码:procedure TForm2.ComboBox3Change(Sender: TObject); //更改税管员
    var s3:string;
    begin
    s3:=copy(combobox3.Text,1,pos('[',combobox3.Text)-1);
    LJClientDataSet8.Close;
    LJClientDataSet8.Provider.DataRequest('select oper_num,oper_name from dsbm.oper_def '+
    'where bumen_code in (select jg_code from dsbm.swjg where jg_code='+s3+')and cxjc=5  order by oper_num / ');
    LJClientDataSet8.Open;
    while not LJClientDataSet8.Eof do
    begin
    combobox4.Items.Add(LJClientDataSet8.fieldbyname('oper_num').asstring+'['+LJClientDataSet8.fieldbyname('oper_name').asstring+']');
    LJClientDataSet8.Next;
    end;
    end;现在的问题是combobox中的内容没有改变高手们帮帮忙啊!!!!!!!
      

  12.   

    在循环之前先清掉
    ComBoBox4.Items.Clear;
    然后再加内容;while   not   LJClientDataSet8.Eof   do 
    begin 
    combobox4.Items.Add(LJClientDataSet8.fieldbyname('oper_num').asstring+'['+LJClientDataSet8.fieldbyname('oper_name').asstring+']'); 
    LJClientDataSet8.Next; 
    end;