Chinaunix首页 | 论坛 | 博客
  • 博客访问: 547761
  • 博文数量: 128
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 1345
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-22 21:43
文章分类

全部博文(128)

文章存档

2009年(30)

2008年(98)

我的朋友

分类:

2008-04-28 11:26:53

TcxDBLookupComboBox的下拉列表可以显示两列,只要在ListColumns中设置多个字段就可以了

当运行时,在下拉列表中选择一列时,TcxDBLookUpComboBox在ComboBox中只能显示一列,
因为在ListFieldIndex中设置显示列



通过修改组件内容(非继承),让它显示两列,包括枚举值

cxDBLookupEdit.pas
主要修改内容:

# 注:ShowAllList为自定义属性,为了是否显示多列
procedure TcxCustomDBLookupEdit.PrepareDisplayValue(
  const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue;
  AEditFocused: Boolean);
begin
  if (not ActiveProperties.ShowAllList) and (ActiveProperties.DropDownListStyle <> lsEditList) and not Focused and
    ActiveProperties.CanDisplayArbitraryEditValue then
      DisplayValue := VarToStr(AEditValue)
  else
    ActiveProperties.PrepareDisplayValue(AEditValue, DisplayValue, AEditFocused);
end;

function TcxCustomDBLookupEditProperties.GetDisplayLookupText(const AKey: TcxEditValue): string;
var
  ARecordIndex: Integer;
  AItemIndex: Integer;
  ADataSet: TDataSet;
  T1 : string;
  T2 : string;
begin
  Result := '';
  AItemIndex := GetListIndex;
  if (AItemIndex <> -1) and (DataController <> nil) then
  begin
    if IsUseLookupList then
    begin

      // TODO: proc?
      if FLookupList.Find(AKey, ARecordIndex) then
        Result := FLookupList[ARecordIndex]^.DisplayText
      else
      begin
        ADataSet := DataController.DataSet;
        LockDataChanged;
        try
          if (ADataSet <> nil) and ADataSet.Active and (ListField <> nil) and
            CanCallDataSetLocate(DataController.DataSet, KeyFieldNames, AKey) and
            ADataSet.Locate(KeyFieldNames, AKey, []) then
            Result := ListField.AsString // ListField.DisplayText
          else
            Result := '';
        finally
          UnlockDataChanged;
        end;
        FLookupList.Insert(ARecordIndex, AKey, Result);
      end;

    end
    else
    begin
      ARecordIndex := GetRecordIndexByKey(AKey);
      if ARecordIndex <> -1 then begin
        if ShowAllList and (GetLookupGridColumnCount = 2)  then begin
          T1 := DataController.DisplayTexts[ARecordIndex, 0];
          T2 := DataController.DisplayTexts[ARecordIndex, 1];
          if SameText(FFormatStr, '') then
             FFormatStr := '%-8s | %-s';
         
          Result := Format(FFormatStr, [T1, T2]);
        end
        else
          Result := DataController.DisplayTexts[ARecordIndex, AItemIndex];
       
      end;
    end;
  end;
end;

拷贝到ExpressEditors Library 5,重新按装DevExpr
ess组件
cxDBLookupEdit
DevExpress\ExpressEditors Library 5\Sources\cxDBLookupEdit.pas
阅读(3327) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~