TMSFNCDataGrid Find

Can someone explain the .Find method?

I want to find a value in a hidden column and automatically scroll to and select that row.
(In this case it's the last column of the grid)
The grid is already configured as gsmSingleRow.

I have this code, but it finds the same value in cell in a different column and selects that row.

// Searches for a value and selects the corresponding row
procedure LookupAndSelect(AGrid: TTMSFNCDataGrid; AColumn: Integer; AValue: string; FocusGrid: Boolean = false);
var
  r: Integer;
  c: TTMSFNCDataGridCellCoord;
  fparams : TTMSFNCDataGridDataFindParameters;
begin
  AGrid.BeginUpdate;
  try
    // Look up the value and select the row
    fparams := [gfnAutoGoto, gfnIncludeHiddenColumns, gfnIncludeHiddenRows, gfnFindInPresetColumn];
    c := AGrid.Find(AValue, fparams);
    r := AGrid.RealToDisplayCell(c).Row;
    if r > 0 then
      AGrid.SelectedRows[r] := true;
  finally
    AGrid.EndUpdate;
  end;

  // Optionally focus the grid after selection
  if FocusGrid then
    AGrid.SetFocus;
end;

Looking at your code and the InternalFind method, I can see the issue. You're using gfnFindInPresetColumn but you're not actually setting which column to search in.

// Set the column to search in before calling Find
AGrid.Options.Find.Column := AColumn;    

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.