New topic: 

Listbox being a pain when sorting

<http://forums.realsoftware.com/viewtopic.php?t=26363>

       Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic         Author  
Message       TomHicks           Post subject: Listbox being a pain when 
sortingPosted: Sat Feb 07, 2009 3:48 pm                        
Joined: Mon Aug 20, 2007 9:42 am
Posts: 76              Simple-ish problem to explain, but seemingly impossible 
to fix.

I have a listbox, and a button.  When the button is clicked, the current 
listbox row becomes editable:
Code:lstTemplates.EditCell lstTemplates.ListIndex, 0

After the cell has been edited, I want the listbox to be sorted, such that the 
changed value fits in with the rest of the list.  I have tried doing this by 
both calling the sort event, and also by repopulating my listbox completely 
from the database - these were placed in the CellAction Event.  The listbox 
sorts fine, but the problem is that the selected row does not follow the new 
sorting.

To test this, I tried the following in various places:
Code:lstMaterials.ListIndex=0

In CellAction, after the line lstMaterials.Sort - no luck.
In SortColumn Event - no luck.
In CellLostFocus - no luck.

It seems that the CellAction event is returning the ListIndex to the row I was 
editing, after the sorting has changed the order.  Though when I've been 
fiddling around putting 'debugging' msgbox lines in my code, it seems that the 
listindiex goes to the correct place, then goes wrong.

Does anyone have a working implementation for this behaviour?  It's really 
beginning to annoy me.   
                            Top               timhare           Post subject: 
Re: Listbox being a pain when sortingPosted: Sat Feb 07, 2009 5:39 pm           
             
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 4348
Location: Portland, OR  USA              CellAction is the wrong place to do 
this.  You're catching the listbox in an indeterminate state.  The simplest way 
to resolve this is with a short period timer (1 ms is enough, just so the sort 
happens *after* the listbox is done processing its event).  In CellAction, 
start a timer, and in the Timer.Action event, do the sort.

Tim   
                            Top               TomHicks           Post subject: 
Re: Listbox being a pain when sortingPosted: Sat Feb 07, 2009 6:57 pm           
             
Joined: Mon Aug 20, 2007 9:42 am
Posts: 76              Yeah I fixed it with a timer in the end.  It's a bit of 
a pain to have to do things like this, due to what is basically a bug in the RB 
Listbox implementation.

As for CellAction being the wrong event, I tried it in CellLostFocus too, which 
should surely fire after the Listbox has finished doing anything it wants after 
editing a cell, but it still doesn't work.   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]     

-- 
Over 900 classes with 18000 functions in one REALbasic plug-in. 
The Monkeybread Software Realbasic Plugin v8.1. 

&lt;http://www.monkeybreadsoftware.de/realbasic/plugins.shtml&gt;

[email protected]

Reply via email to