NizamUlMulk Posted October 3, 2019 Share Posted October 3, 2019 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! How move the scroll programatically until the selected item? Link to comment Share on other sites More sharing options...
NizamUlMulk Posted October 3, 2019 Author Share Posted October 3, 2019 I found! if somebody has same problem. The solution is: with UniListBox1 do JSInterface.JSCall('boundList.getSelectedNodes()['+inttostr(SelCount-1)+'].scrollIntoView', [True]); Solved Link to comment Share on other sites More sharing options...
Servant5166 Posted October 3, 2019 Share Posted October 3, 2019 Where do you apply the code above? Link to comment Share on other sites More sharing options...
NizamUlMulk Posted October 7, 2019 Author Share Posted October 7, 2019 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; 1 Link to comment Share on other sites More sharing options...
jackamin Posted September 9, 2020 Share Posted September 9, 2020 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: 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 More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now