I am trying to get the selected values from a DbADVGrid that has a DataSource linked to a Query with about 300 records returned.
'dbgGrowNames' Is the Grid Name. Code for Double Click on the Grid :
procedure TfrmGinImp.dbgGrowNamesDblClickCell(Sender: TObject; ARow, ACol: Integer);
var
sGrowName, sGrowNum : string;
begin
sGrowName := dbgGrowNames.Cells[1, ARow]);
sGrowNum := dbgGrowNames.Cells[2, ARow]);
...
This Works Correctly.
However, when I want to use an EditBox with a NarrowDown function linked to the Grid the ARow value does not have the correct row for the Grid any more.
I found GetRealRow function.
eg. This is after Grid has been 'NarrowedDown' to about 5-10 records
procedure TfrmGinImp.dbgGrowNamesDblClickCell(Sender: TObject; ARow, ACol: Integer);
var
iActualRow : Integer;
sGrowName, sGrowNum : string;
begin
iActualRow := dbgGrowNames.GetRealRow; // Not the Narrowed Row Number (Arow)
sGrowNum := dbgGrowNames.Cells[2, iActualRow];
with dmClass.qryGrowNames do // This is the Base Query
begin
Locate('Id No', sGrowNum, []);
sGrowName := FieldByName('Sort Name').AsString; // From Query
end; // with
This works sometimes but in most cases the GetRealRow Value is not correct.
Does anyone have any ideas on this.
Did you set grid.PageMode = false?
When grid.PageMode = false, using grid.Cells[x,ARow] should keep working.
Yes, I had PageMode set to False;
I have found a workaround to this by using 'OnDblClick' instead of 'OnDblClickCell' and setting the Row instead of the using ARow passed in 'OnDblClickCell' :
procedure TfrmGinImp.dbgGrowNamesDblClick(Sender: TObject);
var
iActualRow : Integer;
begin
iActualRow := dbgGrowNames.Row;
sGrowNum := trim(dbgGrowNames.Cells[2, iActualRow]);