`
java-mans
  • 浏览: 11427498 次
文章分类
社区版块
存档分类
最新评论

cxgrid中lookupcombobox查找改进

 
阅读更多
//自带的cxgrid并能在lookupcombobox中进行多列查询,在其他地方收集到一些资料,可实现多列查询,但只能从某列的开关开始录入,下面是实现的代码,只是我还想要实现模糊查询,若哪位仁兄做出来,望告知

//将cxgride中的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;


//后面这些修改为使能达到模糊查询,效果还要改进

//cxDataUtils.pas
function DataCompareText(const S1, S2: string; APartialCompare: Boolean): Boolean;
var
   AText1, AText2: string;
   L2: Integer;
begin
   AText1 := AnsiUpperCase(S1);
   AText2 := AnsiUpperCase(S2);
   L2 := Length(AText2);
   if L2 = 0 then
      Result := Length(AText1) = 0
   else
      if not APartialCompare then
         Result := AText1 = AText2
      else
      //修改开始begin
      //Result := (Length(AText1) >= L2) and (Copy(AText1, 1, L2) = AText2); //原语句
      begin
         Result := (Length(AText1) >= L2) and (pos(atext2, atext1) > 0);
      end;
      //修改结束end
end;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics