程序中的TComboBox控件的Style设置为csDropDownList以后,再用代码修改Text属性不好用,还是使用默认的Text。代码如下:
Item属性为:
未婚
已婚
离异
ItemIndex为1
hyzk.Text := TTable1.fieldbyName('marry').AsString;//这句代码不产生作用!
Style属性为csDropDown时就好用。
没办法使Style属性为csDropDownList时,用代码修改Text属性也可以吗?

解决方案 »

  1.   

    ComboBox1.Items[1]:=edit1.Text;或
    Combobox1.ItemIndex:=strtoint(edit2.text);
      

  2.   

    csDropDownList Creates a drop-down list with no edit box; the user cannot enter text manually. All items are strings of the same height.
    这是delphi的帮助,不是写清楚了吗?
    我估计你是希望它不能用手工输,但希望在程序里面控制,那么就在onkeydown里面禁止输入好了
      

  3.   

    这样呢?
    if hyzk.items[i]=TTable1.fieldbyName('marry').AsString then
      hyzk.itemsindex := i;
      

  4.   

    for i:=  0  to   items.count - 1  do
    being
      if hyzk.items[i]=TTable1.fieldbyName('marry').AsString then
    begin
      hyzk.itemsindex := i;
      break;
    end ;
    end ;
      

  5.   

    csDropDownLis 之后 的TEXT从列表中选取,改TEXT没有作用,所以,要修改的话,按楼上的
      

  6.   

    ComboBox1.ItemIndex :=ComboBox1.Items.IndexOf(Query1.fieldbyname('FieldName').asstrin)
      

  7.   

    ComboBox1.ItemIndex :=ComboBox1.Items.IndexOf(Query1.fieldbyname('FieldName').asstring)