Display the item selected in the ListBox

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Display the item selected in the ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:21 pm

by Brett >> Fri, 28 Feb 2003 1:40:34 GMT

Hi,

This is to do with a Form maintaining objects.
When the list box is populated and a vertical scroll bar appears, if you select the last item in the object and go apply to save changes. The list box resets itself and displays the top of the listbox, then you have to scroll down to the bottom to visually see the object.

What is the best way to fix this?

Thanks in advance,
Brett.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Display the item selected in the ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:21 pm

by torrie >> Fri, 28 Feb 2003 8:14:18 GMT

Brett

The listbox has a couple of methods and properties that may help. The first is topIndex which when set puts that item as the top row in the list box. There is also the itemVisible method which you can use to test if the item is visible. You may need to write some code on an appropiate event (eg formLoad) that positions the list box.

Torrie

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Display the item selected in the ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:21 pm

by Patwos >> Wed, 5 Mar 2003 0:58:49 GMT

Brett,

You didn't indicate in your message, but I'll presume the listBox is being populated using listCollection and it's the notification that occurs when you apply your changes resulting in the listBox repopulating the listBox that is causing you some grief. You may want to consider sending a request to Jade Support for an option on the listBox for this to happen automatically.

In the interim, as you have limited control over when the listBox is going to receive/process the notification you need to find a way of actioning your code immediately after the listBox finishes processing it's notification. As the listBox in turn calls displayEntry to get the string to use for the "addItem" for a given row, you can utilise this as follows. Let's asume that when the user clicks/doubleClicks and entry in the listbox that they want to edit, you set a 'myCurrentC1' type reference on the form. Then, in the displayEntry method you could have something like the following: --------------------------------------------------------------------------- ---------------
listBox1_displayEntry(listbox: ListBox input; c1 : Class1; lstIndex: Integer):String updating;

vars

begin
if c1 = myCurrentC1 then
// Very short timer as we want the illusion of this
// happening without any visible delay
beginTimer( 10, Timer_OneShot, 99 );
endif;
return c1.someStringProperty ;
end; --------------------------------------------------------------------------- ---------------

This will mean that if myCurrentC1 is not null, when displayEntry is called for the instance of c1 that matches your current c1 a timer is armed. The reason for the if is to avoid attempting to arm the timer twice and to only arm the timer if you are currently or have just edited an entry.

Your timer event would then process the following code to make the topIndex the last object you edited: --------------------------------------------------------------------------- ---------------
timerEvent(eventTag: Integer) updating;

vars

begin
if eventTag = 99 then
listBox1.topIndex := listBox1.findObject( myCurrentC1 );
endif;
end; --------------------------------------------------------------------------- ---------------
Note: If this would not fill the listBox, the topIndex will be reduced until the listBox is full, but it still achieves the desired result of having the currently selected entry visible.

I'd still recommend putting in a request to Jade Support asking for an option for the listbox to do this automatically since that is probably what would be wanted for most applications.

Hope that helps,
Patwos.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 30 guests