View previous topic :: View next topic |
Author |
Message |
IncProg
Joined: 30 Apr 2009 Posts: 6
|
Posted: Sun Aug 11, 2013 8:43 am Post subject: Is it possible to prohibit selection of multiple levels ? |
|
|
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 |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Aug 12, 2013 5:54 am Post subject: |
|
|
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 |
|
|
IncProg
Joined: 30 Apr 2009 Posts: 6
|
Posted: Mon Aug 12, 2013 10:17 am Post subject: |
|
|
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 |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Aug 12, 2013 10:46 pm Post subject: |
|
|
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 |
|
|
IncProg
Joined: 30 Apr 2009 Posts: 6
|
Posted: Thu Aug 15, 2013 7:57 am Post subject: |
|
|
Thank you for answer.
Your code helped me very much. |
|
Back to top |
|
|
|