Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Location of Selected Row in Grid After a Find
Wed, Oct 10 2018 8:32 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

When I do a Find to locate an item in a grid, the selected row is displayed as the last item.

To ensure that the user can see the selected row in relationship to adjacent rows, I perform the following which works but seems very inelegant. If there is more than 6 rows in the grid, it will display the selected row with 6 rows below it. I cannot work out another way. Does anyone have a better suggestion? Many thanks.

Richard

  with Grid2.DataSet do
  begin
     InitFind;
     Columns['Category'].AsString := fCurrentCategory;
     Columns['Number'].AsInteger := fCurrentStockNumber;

     if (not Find) then
     begin
        if isAppending
           then Last
           else First;
     end else
     begin
        MaxRowsToMove := 6;
        RowsToMove := RowCount - RowNo;

        if RowsToMove < MaxRowsToMove then
        begin
           MoveBy(RowsToMove);
           MoveBy(-RowsToMove);
        end else
        begin
           MoveBy(MaxRowsToMove);
           MoveBy(-MaxRowsToMove);
        end;
     end;
  end;  //with Grid2.DataSet
Tue, Oct 16 2018 3:00 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< To ensure that the user can see the selected row in relationship to adjacent rows, I perform the following which works but seems very inelegant. If there is more than 6 rows in the grid, it will display the selected row with 6 rows below it. I cannot work out another way. Does anyone have a better suggestion? Many thanks. >>

What is the desired result ?  Do you want to have the selected row be centered within the visible rows, or at the top... ?

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Oct 17 2018 2:39 PMPermanent Link

jdforce

Avatar

Tim,
I have the same problem. For me, the desired result is to have the result on the top of the list.  That is what the user expect, at least in my case.

Then I need to highlight the whole row or a cell. but that is another story, on another post I made..
Tue, Oct 23 2018 2:19 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< I have the same problem. For me, the desired result is to have the result on the top of the list.  That is what the user expect, at least in my case. >>

Use this for now:

  Grid1.ScrollTo(Grid1.RowIndex);

That will position the row index at the *top* of the grid, instead of being positioned at the end.

Also, using DisableControls/EnableControls will work:

  with Customers do
     begin
     DisableControls;
     try
        InitFind;
        Columns['CustNo'].AsFloat:=3984;
        Find;
     finally
        EnableControls;
     end;
     end;

The basic problem is that InitFind causes the row index to move to the first row (it uses a "fake" first row for allowing find input), so any subsequent find operations are always moving from the top of the dataset to the bottom of the dataset.  Using DisableControls/EnableControls prevents the InitFind from causing the row index to move to the "fake" row.  So, if you execute a find operation that moves the row index *backward*, then this fix will cause the row index to be on the *first* visible row instead of the *last* visible row.

What is really necessary is just a one-shot Find operation that doesn't rely on populating columns in order to perform the find.  I'll have to try to find time to sneak something in for EWB 3.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Oct 25 2018 1:58 AMPermanent Link

Richard Harding

Wise Nutrition Coaching

<<What is the desired result ?  Do you want to have the selected row be centered within the visible rows, or at the top... ?>>

Tim,

The customer wants to be able to view the selected row in context with the other rows. So, having the selected row centered in the window would be a good option.

Richard
Image