Jump to content

How to show the user a specific line of TUniListBox?


Tokay

Recommended Posts

I've tried two methods found on the forum:

 with UniListBox1 do
  JSInterface.JSCall('boundList.getSelectedNodes()[' + ItemIndex.ToString + '].scrollIntoView', [True]);

 with UniListBox1 do
  JSInterface.JSCall('boundList.getSelectedNodes()[' + ItemIndex.ToString + '].scrollIntoViewIfNeeded', [True]);

or just 'getSelectedNodes()[0].scrollIntoView'

I always get the same error:

JS Error: Cannot read properties of undefined (reading 'scrollIntoViewIfNeeded')

Link to comment
Share on other sites

UniListBox1.ItemIndex := 0;
with UniListBox1 do
 if ItemIndex <> -1 then
  JSInterface.JSCall('boundList.getSelectedNodes()[0].scrollIntoViewIfNeeded', [True]);

Ok, I've change code to this one. And issue still exists : JS Error: Cannot read properties of undefined (reading 'scrollIntoViewIfNeeded')

What I'm missing?

Link to comment
Share on other sites

41 minutes ago, Tokay said:

test case.7z 54.83 kB · 0 downloads

Please read the above post, I have already given you a solution.

1.

7 hours ago, Sherzod said:

Or add this client event:

function afterCreate(sender)
{
    var list = sender.boundList;
    list.on('select', function(){list.getSelectedNodes()[0].scrollIntoViewIfNeeded()});
}

2.

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin
 UniListBox1.ItemIndex := 0;
 //with UniListBox1 do
  //if ItemIndex <> -1 then
   //JSInterface.JSCall('boundList.getSelectedNodes()[0].scrollIntoViewIfNeeded', [True]);
end;

 

Link to comment
Share on other sites

Hmm. This is only the test case. In the real case I need to show the currently selected line, and this line is not the zero line:

 with UniListBox1 do
  JSInterface.JSCall('boundList.getSelectedNodes()[' + ItemIndex.ToString + '].scrollIntoView', [True]);

 with UniListBox1 do
  JSInterface.JSCall('boundList.getSelectedNodes()[' + ItemIndex.ToString + '].scrollIntoViewIfNeeded', [True]);

Link to comment
Share on other sites

9 hours ago, Tokay said:

This is only the test case. In the real case I need to show the currently selected line, and this line is not the zero line:

it seems we don't understand each other! 

You are still using this code:

9 hours ago, Tokay said:

with UniListBox1 do
  JSInterface.JSCall('boundList.getSelectedNodes()[' + ItemIndex.ToString + '].scrollIntoViewIfNeeded', [True]);

Do not use it, instead, use what I gave you:

19 hours ago, Sherzod said:

Or add this client event:

function afterCreate(sender)
{
    var list = sender.boundList;
    list.on('select', function(){list.getSelectedNodes()[0].scrollIntoViewIfNeeded()});
}

 

Link to comment
Share on other sites

Ok. It starts well, no problem. But after I, for example, scroll UniListBox1 to the first line, and it does not returns bak automatically as needed to the neded 50 position. And it's logical: the Timer does not execute any code.

I repeat: whatever user or code do with UniListBox1 is needed to maximally show 50 line for the user as possible until form closed.

Link to comment
Share on other sites

9 hours ago, Tokay said:

It starts well, no problem. But after I, for example, scroll UniListBox1 to the first line, and it does not returns bak automatically as needed to the neded 50 position. And it's logical: the Timer does not execute any code.

I repeat: whatever user or code do with UniListBox1 is needed to maximally show 50 line for the user as possible until form closed.

Okay.

I think mistake in the code was that you specified the ItemIndex of the selected row (UniListBox1). That's not so.

Should always be zero. 

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin
 with UniListBox1 do
  if ItemIndex <> -1 then
   JSInterface.JSCall('boundList.getSelectedNodes()[0].scrollIntoViewIfNeeded', [True]);
end;

 

Link to comment
Share on other sites

  • 3 months later...
On 9/28/2021 at 8:26 AM, Sherzod said:
JSInterface.JSCall('boundList.getSelectedNodes()[0].scrollIntoViewIfNeeded', [True]);

 

Подскажите, как прокрутить программно список TUniListBox до нужной или до выбранной строки?

Этот код у меня не работает.

Идея такая. На форме лежит отсортированный TUniListBox, пользователь добавляет строку и нужно до нее прокрутить автоматически.

Link to comment
Share on other sites

Сразу после добавления строки.

 

Но... я взял пример выше и добавил кнопку и код

 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
 with UniListBox1 do
  if ItemIndex <> -1 then
   JSInterface.JSCall('boundList.getSelectedNodes()[50].scrollIntoViewIfNeeded', [True]);
end;

нажимаю ее и ничего не происходит

Screenshot_6.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...