让DevExpress V4 的 LookupComboBox 可以多列查询。

  • 内容
  • 评论
  • 相关

经分析修改以下两个文件即可达到目标
cxCustomData.pas 
修改一

  TcxCustomDataController = class(TPersistent, IUnknown)
  private
    FDisplayIndex: Integer; --添加一个属性
    FActive: Boolean;
    FAfterSummaryFlag: Boolean;
    FBookmarkRecordIndex: Integer;
...
  public
     property DisplayIndex: Integer  read FDisplayIndex write FDisplayIndex; --把属性公布出来

修改二

function TcxCustomDataController.DoIncrementalFilterRecord
  (ARecordIndex: Integer): Boolean;
var
  S: string;
  I: Integer;
begin
  Result := False;
  for I := 0 to Fields.ItemCount - 1 do
  begin
    S := GetInternalDisplayText(ARecordIndex, Fields[I]);
    Result := DataCompareText(S, FIncrementalFilterText, True);
    if Result then
    begin
      FDisplayIndex := I;
      Exit;
    end;
  end;
  // 注释掉原来的代码
  // S := GetInternalDisplayText(ARecordIndex, FIncrementalFilterField);
  // Result := DataCompareText(S, FIncrementalFilterText, True);
end;

cxLookupEdit.pas
修改一

function TcxCustomLookupEditLookupData.Locate(var AText, ATail: string;
  ANext: Boolean): Boolean;
  function SetGridFilter(AItemIndex: Integer; const AText: string): Integer;
  ...
  var
    AItemIndex, ARecordIndex: Integer;
    S: string;
  begin
    Result := False;
    DisableChanging;
    try
      AItemIndex := GetListIndex;
      if (AItemIndex <> -1) and (DataController <> nil) then
      begin
        // TODO: Next
        if FVisible and
          Properties.GetIncrementalFiltering 
          { and (Properties.DropDownListStyle <> lsFixedList) }
        then
          ARecordIndex := SetGridFilter(AItemIndex, AText)
        else
          ARecordIndex := Properties.FindByText(AItemIndex, AText, True);
        if ARecordIndex <> -1 then
        begin
          DataController.ChangeFocusedRecordIndex(ARecordIndex);
          DoSetCurrentKey(ARecordIndex);
          Result := True;
          // 此处为添加代码
          if DataController.DisplayIndex > -1 then
          begin
            S := DataController.DisplayTexts[ARecordIndex,
              DataController.DisplayIndex];
            DataController.DisplayIndex := -1;
          end
          else
          begin
            S := DataController.DisplayTexts[ARecordIndex, AItemIndex];
          end;
          // 结束
          AText := Copy(S, 1, Length(AText));
          ATail := Copy(S, Length(AText) + 1, Length(S));
          DoSetKeySelection(True);
        end
        else
          DoSetKeySelection(False);
      end;
    finally
      EnableChanging;
    end;
  end;

经过以上修改重新编译就可以了。

评论

2条评论
  1. Gravatar 头像

    老刘 回复

    能实现输入条件,自动下拉码?而且还是模糊查询

  2. Gravatar 头像

    Aly Chiman 回复

    Hello there,

    My name is Aly and I would like to know if you would have any interest to have your website here at 2lin.net promoted as a resource on our blog alychidesign.com ?

    We are in the midst of updating our broken link resources to include current and up to date resources for our readers. Our resource links are manually approved allowing us to mark a link as a do-follow link as well
    .
    If you may be interested please in being included as a resource on our blog, please let me know.

    Thanks,
    Aly

发表评论

电子邮件地址不会被公开。 必填项已用*标注