Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sorting and Selecting

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
Stuart
Guest





PostPosted: Tue Feb 21, 2006 12:02 am    Post subject: Sorting and Selecting Reply with quote

I've been messing around with virtual tree for a couple of days now, and have a couple of questions.

I have a list of objects A, when I click a column I handle the SortColumnChanged event and sort it, then run a filter to refill list B, which is the list bound to the virtualtree. Anyway, once the filter is run it does a treeview.UpdateRows(). The thing is, if I'm looking at the top of the list when I sort, then the list will sort but then the only shown item will be the bottom one, and the rest of the list will be empty as if it's scrolled off the bottom (see left of picture) I can scroll up to see the rest (right). Am I doing something wrong? The examples don't do this, and it doesn't do it when I don't call UpdateRows, but sometimes the list doesn't get updated this way.

http://img208.imageshack.us/my.php?image=vtree0mi.jpg

Another thing, if I select all items in a list (like a CTRL+A) the memory use of the list more than doubles, and it takes a few seconds to respond, is this expected?
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Feb 21, 2006 9:06 am    Post subject: Reply with quote

Not quite sure what is going on with your sorting. If you have selected an item the virtual tree tries to keep the current focus item in view when you resort the data. Is it doing the same thing if you don't select anything before sorting? If you could send a sample project to support@infralution.com we would be happy to take a look.

If you select all rows then virtual tree has to retrieve the data for all the rows. If you have a very large data source this could easily lead to a big increase in memory and take some time. If you still want to provide this facility you may want to make use of the SelectionChanging event. This is fired prior to the selected objects being loaded and gives you a chance to cancel the selection. You might use this to warn the user if they are selecting a very large number of items and allow them to opt out.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Stuart
Guest





PostPosted: Tue Feb 21, 2006 3:25 pm    Post subject: Reply with quote

I've emailed the example program. It does happen when nothing is selected yes, which is odd as you'd expect it not to scroll, and it doesn't without the call to UpdateRows().
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Feb 21, 2006 11:14 pm    Post subject: Reply with quote

You don't need to call UpdateRows from within your SortColumnChanged event. Virtual Tree automatically calls this after raising the event. Before calling UpdateRows VirtualTree saves some information about the current focus row and ensures that this row is visible after the call to UpdateRows(). Because you are not doing this your call to UpdateRows() screws up the position.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Stuart
Guest





PostPosted: Tue Feb 21, 2006 11:59 pm    Post subject: Reply with quote

Thanks for that, is there any way to stop it calling UpdateRows() though? The reason I was having to call it manually is that when handling the sort I threw the sorting onto a new thread, so the sort was finishing after exiting SortColumnChanged, and so it didn't seem like it was updating. I've just tried Suspend/ResumeDataUpdate, but on resume it only updates the showing items, scrolling down the list everything is in the wrong order.

Thanks.
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Feb 22, 2006 12:18 am    Post subject: Reply with quote

I'm not sure what you really gain here by doing the sort on a separate thread. While it might allow the user to continue using the interface for a short period it will then be rather surprising for them to have the display suddenly change if the sort is completed say 10 seconds later. They will also probably wonder whether the original sort click did anything and click 10 more times (if I know anything about users Rolling Eyes )

You could prevent the UpdateRows from happening by deriving a new class from VirtualTree and overriding the OnSortColumnChanged method. You'd then have to handle the UpdateRows and maintaining the correct position yourself. For reference the default implementation of OnSortColumnChanged is given below:

Code:
       
        protected virtual void OnSortColumnChanged()
        {
            SuspendLayout();
            if (SortColumnChanged != null)
            {
                SortColumnChanged(this, new System.EventArgs());
            }
            int index = TopRowIndex;
            UpdateRows(true);
            TopRowIndex = index;
            if (SelectedRow != null)
            {
                SelectedRow.EnsureVisible();
            }
            ResumeLayout(false);
            PerformLayout();
        }


If you do still want to use a separate thread you'll have to be really careful. Threading introduces all sorts of possible pitfalls. Any calls you make to Virtual Tree from other threads will need to be marshalled onto the main windows forms thread using the Control.Invoke or Control.BeginInvoke method (search these forums for more info). This is because windows forms is not thread safe.

For really large amounts of data you are almost certainly better off with a database approach. See the Database Browser sample which uses our Virtual Data Objects product to give very good performance for large amounts of data (sorting is near instantaneous).
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Stuart
Guest





PostPosted: Wed Feb 22, 2006 12:42 am    Post subject: Reply with quote

Thanks again, I'll have a mess around with that code later.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group