Jump to content

TUniListBox scroll programatically


NizamUlMulk

Recommended Posts

image.png.7f006e73bd82a2506d94e97a37e8cacf.png  When key press over the list box (multiselect and ordered), the item is selected, but the scroll doesn´t move to that item.

Ex. Press G words from the keyboard and listbox stays same as before, but, if manually scroll the list until found an item beginning with G, that item seems selected!
image.png.3643f7c939166f7405841dab9de06cb2.png

How move the scroll programatically until the selected item?

 

 

Link to comment
Share on other sites

procedure TMainForm.myListKeyPress(Sender: TObject; var Key: Char);
var vector: TArray<string>;
    index: Integer;
begin
  with TUniListBox(Sender) do begin
    if Items.Count = 0 then Exit;
    Key := UpCase(Key);
    vector := Items.ToStringArray;
    TArray.BinarySearch<string>(vector, Key, index, TStringComparer.Ordinal);
    if index > -1 then begin
      ItemIndex := index;
      JSInterface.JSCall('boundList.getSelectedNodes()['+inttostr(SelCount-1)+'].scrollIntoView', [True]);
      Selected[index] := False;
    end;
  end;
end;

 

  • Like 1
Link to comment
Share on other sites

  • 11 months later...

Hello,

First of all, thank you for sharing your solution! Unfortunately, it did not work for me in Delphi XE10, in a UniGui application that runs in synchronous mode. I got the following error message:

image.png.5bd8ebf70709fec8a2fbfdf54ae76a88.png

 

HOWEVER! I was able to fix the problem by calling UniSession.Synchronize() between the Delphi code and the JavaScript code.

The following worked for me:

UniListBox1.ItemIndex:=11;
UniSession.Synchronize();
UniListBox1.JSInterface.JSCall('boundList.getSelectedNodes()[0].scrollIntoView', [True]);

Note that I hard-coded '0' as the selected node index. This is because UniListBox1 does not have multi-select enabled.

Also note that, in the MainModule, the EnableSynchronousOperations property must be set to 'True' to use UniSession.Synchronize(), but you should read this guide before deciding to run your application in synchronous mode.

 

Hope it helps someone!

-Jack

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...