View previous topic :: View next topic |
Author |
Message |
gregoryagu
Joined: 12 Dec 2007 Posts: 78
|
Posted: Mon Nov 03, 2008 4:11 pm Post subject: Selecting Multiple Items Programmatically |
|
|
I have a virtual tree which uses object binding.
The tree allows a copy/paste feature which allows one object to be in the tree in two places at the same time.
When the user selects reference 1 in the tree, I would like to also select reference 2. Thus they would both be highlighted in the tree.
Is there a way this can be done?
Greg |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Nov 03, 2008 10:37 pm Post subject: |
|
|
Yes - handle the SelectionChanged event. Then locate the Row for the second item using one of the FindRow or FindRowByIndex methods. Then call virtualTree.SelectedRows.Add() to add the row to the selection. _________________ Infralution Support |
|
Back to top |
|
|
gregoryagu
Joined: 12 Dec 2007 Posts: 78
|
Posted: Tue Nov 04, 2008 3:11 pm Post subject: |
|
|
The FindRow(object) method finds the first row to match. But if there are two of the same object, it will not find the second one, only the first. So if the user selects the second object, it will find the first, and then both are highlighted.
But if the user selects the first one, the second one is not found. And if there was a 3rd or a 4th, these would not be found either.
Greg |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Nov 04, 2008 9:29 pm Post subject: |
|
|
Yes you would need to use the overloaded version of FindRow(IList) or use FindRowByIndex. These allow you to specify the full path to the item.
You should consider whether you really want to do this. If both items are always selected together it means that the user won't be able to select one item and move it to another location or delete it. So once they create the aliasing using copy/paste they are stuck with it.
An alternative way of highlighting the aliased row (without actually selecting it) would be to create a custom RowWidget/CellWidget and override the GetActiveStyle methods - something like:
Code: | public override Style GetActiveStyle()
{
if (Row.Selected)
return base.GetActiveStyle();
else
{
foreach (Row row in Tree.SelectedRows)
{
if (row.Item.IsEqual(Row.Item))
return GetSelectedStyle();
}
}
return base.GetActiveStyle();
} |
_________________ Infralution Support |
|
Back to top |
|
|
gregoryagu
Joined: 12 Dec 2007 Posts: 78
|
Posted: Tue Nov 18, 2008 7:28 pm Post subject: |
|
|
OK, thanks for the suggestions.
Greg |
|
Back to top |
|
|
|