为TDBLookupComboboxEh增加自定义列宽

 为TDBLookupComboboxEh增加自定义列宽,用于设置下拉框中各列的宽度,而避免必须用DropDownBox才能设置的问题。

TCustomDBLookupComboboxEh = class(TCustomDBEditEh, ILookupGridOwner)
Private  
  FListWidths: string;
  procedure SetListWidths(const Value: string);
public
  property ListWidths: string read FListWidths write SetListWidths;
end;    
    
// 源字符串按照分隔符分割成TstringList,返回生成的行数
function StringToList(AList: TStrings; AString,
  ASeparator: string;AClear: Boolean): Integer;
var
  cStr : string;
  i : Integer;
begin
  Result := 0;

  if AClear then AList.Clear;
  if AString = '' then Exit;
  
  cStr := AString;
  i := Pos(ASeparator,cStr);
  while i <> 0 do
  begin
    AList.Add(Copy(cStr,0,i -1));
    Delete(cStr,1,i);
    i := Pos(ASeparator,cStr);
  end;
  AList.Add(cStr);
  Result := AList.Count;
end;

function CountCharInStr(const Sub: Char; const AStr: string): Integer;
var
  I: Integer;
begin
  Result := 0;
  if AStr = '' then Exit;
  for I := 1 to Length(AStr) do
    if AStr[I] = Sub then
      Inc(Result);
end;

procedure TCustomDBLookupComboboxEh.SetListWidths(const Value: string);
var
  lStr1,lStr2: TStrings;
  i,iLen,iSum: Integer;
begin
 //  FDataList.Columns.Add

  //设置下拉列表框的字段宽度
  if FListWidths <> Value then
  begin
    FListWidths := Value;

    FDataList.Columns.Clear;
    //FDropDownBox.Columns.Clear;

    //FListFieldName 与 FListWidths 中的节数相同
    if (FListFieldName <> '') and (CountCharInStr(';',FListFieldName) = CountCharInStr(';',FListWidths)) then
    begin
      lStr1 := StringToList(FListFieldName,';');
      lStr2 := StringToList(FListWidths,';');
      iSum := 0;
      for i := 0 to lStr2.Count - 1 do
      begin
        if (lStr1[i] = '') then Continue;
        iLen := StrToIntDef(lStr2[i],100);
        iSum := iSum + iLen;
        //with FDropDownBox.Columns.Add do
        with FDataList.Columns.Add do
        begin
          FieldName := lStr1[i];
          Width := iLen;
        end;
      end;
      FDropDownBox.Width := iSum;
      lStr1.Free;
      lStr2.Free;
    end;
  end;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值