我现在的combobox的style属性设为:csDropDownlist
但是我查询时,相应的combobobx就显示不了值。
我该怎么做了?

解决方案 »

  1.   


    但是从数据库中查询的结果就只有一个啊,比如数据库中该combobox存放的性别,它只有男和女,显示的时候也就只能显示一个值。
      

  2.   

    我的意思是:我的combobox是和数据库有关系的,比如,现在这个combobox是用来选择性别的,当查询的时候,如果数据库中该性别的值为“男”,那么在现在的时候combobox就应该显示“男”,问题就是我把combobobx的style属性设为:csDropDownlist 后,combobox就不显示值“男”。
    如果不将style属性设为:csDropDownlist 
    ,到可以显示值“男”,那样combobox就不是只读了。
    不知道明白没有?
      

  3.   

    delphi中的combobox那有readonly这个属性哦?
      

  4.   

    不会吧,是不是在执行sql语句后没有指定combobox的itemIndex属性?
      

  5.   

    我的代码是:
    procedure TForm15.DBEdit1Change(Sender: TObject);
    begin
    dw.Style:=csDropDown;
    combobox1.Style:=csDropDown;
    combobox2.Style:=csDropDown;
    dw.Text:='';
    zg_num.Text:='';
    zg_xm.Text:='';
    age.Text:='';
    Combobox1.Text:='';
    Combobox2.Text:='';
    If DBEdit1.Text= '' Then Exit
    else begin
    ADOQuery4.Close;
    ADOQuery4.SQL.Clear;
    ADOQuery4.SQL.Add('select * from gh_ghxx where dw_zg_num='''+DBEdit1.Text+''' ');
    ADOQuery4.Open;
    dw.Text:=ADOQuery4.fieldbyname('dw_name').AsString;
    zg_num.Text:=ADOQuery4.fieldbyname('dw_zg_num').asstring;
    zg_xm.Text:=ADOQuery4.fieldbyname('dw_zg_name').asstring;
    age.Text:=ADOQuery4.fieldbyname('dw_zg_age').asstring;
    Combobox1.Text:=ADOQuery4.fieldbyname('dw_zg_xb').asstring;
    Combobox2.Text:=AdoQuery4.fieldbyname('dw_zg_xl').AsString;
    DateTimePicker1.DateTime:=strtodate(ADOQuery4.fieldbyname('dw_zg_time').asstring);
    end;
    dw.Style:=csDropDownlist;
    combobox1.Style:=csDropDownlist;
    combobox2.Style:=csDropDownlist;end;
      

  6.   

    如果设置为csDropDownList时,你再赋值时要动态的符值,用combobox.text := 你的值,这样是不行
    得这样var
      i: integer;
    begin
      for i:= 0 to Combobox1.Items.Count-1 do
      begin
        if combobox1.Items[i] = 你的值 then
        begin
          combobox1.ItemIndex := i;
          break;
        end;
      end;
    end;
      

  7.   

    阿日是对的....
    csDropDownlist时,combobox.text属性是不能直接赋值的,你得指定你的列表项作为combobox.text的值
    Itemindex=0 代表把列表框的第一项作为combobox.text
    Itemindex=1 代表把列表框的第二项作为combobox.text
      

  8.   

    非常简单。下面的三行代码即可满足你的需要:combobox1.Items.Add('保存有内容');
    combobox1.Style:=csDropDownList; //设置只读。
    combobox1.ItemIndex:=0; //使第一项选中。
      

  9.   

    这样就可以实现的:(假设你已经设置好了TCombobox中的内容)
    男:
    cbbSex.ItemIndex := cbbSex.Items.IndexOf('男');
    女:
    cbbSex.ItemIndex := cbbSex.Items.IndexOf('女');