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 

Is it possible to prohibit selection of multiple levels ?

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



Joined: 30 Apr 2009
Posts: 6

PostPosted: Sun Aug 11, 2013 8:43 am    Post subject: Is it possible to prohibit selection of multiple levels ? Reply with quote

Is it possible to prohibit selection of multiple levels in the tree ?
I mean if user selected rows in level 2 for instance, it not allowed
to select rows of level 1.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Aug 12, 2013 5:54 am    Post subject: Reply with quote

Yes - you can handle the SelectionChangingEvent (or override OnSelectionChanging) and check (if the change is an Add) that the rows being added are at the same level as the existing SelectedRows (if any). If they are at a different level then set the Cancel flag. This will prevent the selection occuring.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
IncProg



Joined: 30 Apr 2009
Posts: 6

PostPosted: Mon Aug 12, 2013 10:17 am    Post subject: Reply with quote

That's not clear.
And I'm always getting "ClearAndAdd" value in the "SelectionChanging" event.

Can you just bring a little sample of code ?

Thank you.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Aug 12, 2013 10:46 pm    Post subject: Reply with quote

Here is some code:

Code:
private void _virtualTree_SelectionChanging(object sender, SelectionChangingEventArgs e)
{
    if (e.Change == SelectionChange.Add || e.Change == SelectionChange.ClearAndAdd)
    {
        int selectionLevel = -1;
        if (e.Change == SelectionChange.Add && _virtualTree.SelectedRow != null)
        {
            selectionLevel = _virtualTree.SelectedRow.Level;
        }
        for (int i = e.StartRow.RowIndex; i <= e.EndRow.RowIndex; i++)
        {
            Row row = _virtualTree.GetRow(i);
            if (selectionLevel != -1)
            {
                if (row.Level != selectionLevel)
                {
                    e.Cancel = true;
                    break;
                }
            }
            else
            {
                selectionLevel = row.Level;
            }
        }
    }
}

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
IncProg



Joined: 30 Apr 2009
Posts: 6

PostPosted: Thu Aug 15, 2013 7:57 am    Post subject: Reply with quote

Thank you for answer.
Your code helped me very much.
Back to top
View user's profile Send private message
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