combobox3下拉框中的内容我是通过如下方法得到的,我在选择下拉框内容的时候,GchItemID和GchItemName都显示在combobox3的text中了,我想选择下拉框中内容的时候让combobox3的text中只显示GchItemID,请问如何实现? combobox3.Clear;
  FenBaoGchl1.SQL.Clear;
  FenBaoGchl1.SQL.Add('select distinct GchItemID,GchItemName from FenBaoGchl where FbID='+quotedstr(trim(combobox4.Text))+'and XMB='+quotedstr(trim(form23.Edit1.text))+'order by GchItemName asc ');
  FenBaoGchl1.Prepared;
  FenBaoGchl1.Open;
  FenBaoGchl1.first;
  while not FenBaoGchl1.Eof do
  begin
  combobox3.Items.Add(FenBaoGchl1.Fieldbyname('GchItemID').AsString+'——'+FenBaoGchl1.Fieldbyname('GchItemName').AsString);
  FenBaoGchl1.Next;
  end;

解决方案 »

  1.   

    首先将TComboBox的Style属性设为csOwnerDrawFixed,然后在OnDrawItem事件中:
      with ComboBox1 do
      begin
        Canvas.FillRect(Rect);
        if odSelected in State then
        begin
          Canvas.Font.Color := clWhite;
          Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, '你的ID值,可以根据Index这个参数从数据集中取');
        end
        else begin
          Canvas.Font.Color := clBlack;
          Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, Items[Index]);
        end;
      end;
      

  2.   

    '你的ID值,可以根据Index这个参数从数据集中取'
    怎么取啊?可以详细告诉我吗?
      

  3.   

    在OnDrawItem事件中在一个Index参数,表示是第几个下拉选项,你可以根据这个参数定位到某条记录吧,然后取出相应的字段值就行了。
      

  4.   

    数据库编程很久没做了,下面是临时想的方法,可能有更好的方法,
    i := 0;
    DataSet.First;
    while i < Index do
      DataSet.Next;
    这样就定位到这条记录了。
      

  5.   

    while i < Index do
    begin
      DataSet.Next;
      Inc(i);
    end;