【问题标题】:Locate a record in a TDBAdvGrid with PageMode off在关闭 PageMode 的情况下在 TDBAdvGrid 中查找记录
【发布时间】:2013-05-05 13:10:37
【问题描述】:

我正在拼命地尝试对 PK 与 TDBAdvGrid 中的第 0 列相关联的记录进行定位。我拥有的 TMS 组件包版本是 6.8.something。 我在带有 Delphi XE 1 的 Win7x64 中使用它。 PageMode 已关闭,因为我需要在客户端级别进行排序和分组(目前没有后端数据库,只有处于离线模式的客户端数据集)。

我的定位代码是这样的:

procedure TMainFrm.EditAction;
var ItemID : Integer;
    ItemIDStr: String;
begin
  // With PageMode set to false(which we need), the dataset is not synchronized.
  //ItemID := GetActionGrid.Columns[ 0 ].Field.AsInteger;
  ItemIDStr := GetActionGrid.Cells[ 0,GetActionGrid.SelectedRow[ 0 ] ];
  ItemID := StrToIntDef( ItemIDStr ,-1 );
//  GetActionGrid.Fields[ 0 ].AsInteger;
  If DMMain.CLNActions.Locate( 'ITEM_ID',ItemID,[] ) Then
    CreateApplicationForm( TActionFrm, True );
end;

但它不起作用,因为 ItemIDStr 总是返回一个空字符串。 我现在真的很缺乏想法。

建议?

谢谢!

【问题讨论】:

  • 有趣的是,我创建了一个计算字段,它将 ITEM_ID 转换为字符串,并且与该代码非常相似的代码(除了 col 0)确实可以使用该技巧。问题是,此时 ITEM_ID 变得可见(我不想要的东西)并且似乎没有办法隐藏它。
  • 我尝试的另一件事是使用 Column 0(=zero) 的 Ints 属性检索 Int 值。那也不行。我真的不明白。

标签: delphi tms


【解决方案1】:
function TFrameDBGrid1.GrFindValInCol(FldName, FldVal : String) : boolean; //search value in a certain column of the grid
var
   StartCell:TPoint;
   FindParams: TFindParams;
   rv:TPoint;
   CurrCol: integer;
  I: Integer;
const CResultInvalidInt=-1;
begin
  Result := false;
  StartCell.x := CResultInvalidInt;
  StartCell.y := CResultInvalidInt;
  CurrCol := GetColumnIndexOfField(FldName);
  grdGlobal.FindCol := CurrCol;
  FindParams := [fnMatchRegular, fnFindInPresetCol];
  rv:=grdGlobal.Find(StartCell, FldVal, FindParams);
  Result:= (rv.x <> CResultInvalidInt) and (rv.y <> CResultInvalidInt);
  if Result then
    if grdGlobal.Row <> rv.y then
      grdGlobal.Row := rv.y;
end;

【讨论】:

  • 请添加几行解释以帮助您掌握答案的要点。
  • 确实,我回家后会试试(为什么堆栈溢出不通知你答案?)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多