View previous topic :: View next topic |
Author |
Message |
Canavaro
Joined: 28 Oct 2005 Posts: 2
|
Posted: Fri Oct 28, 2005 9:26 am Post subject: FindRow(object item) == null |
|
|
Hello,
this function doesn't work and return null, though I can find this object attached to one of the rows.
Can you help me ? I have the latest version of Virtual Tree. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Oct 28, 2005 11:30 am Post subject: |
|
|
Have you read the section in the online help called "Working with Rows"? For this method to work you need to have set up the Parent property (or handled the GetParent event/method for programmatic binding). This enables VirtualTree to uniquely locate a row based on the object identity. If you haven't done this or there is some other problem Virtual Tree will print out a diagnostic message to the Output window to help you track down what the problem might be. So run your project in the debugger and check the output window. _________________ Infralution Support |
|
Back to top |
|
|
Canavaro
Joined: 28 Oct 2005 Posts: 2
|
Posted: Fri Oct 28, 2005 12:04 pm Post subject: |
|
|
This code finds target row:
Code: |
Row FindRow(Row root_row, object item)
{
if (root_row.Item == null)
return null;
if (root_row.Item.Equals(item))
return root_row;
IList childs = root_row.ChildItems;
if (childs == null || childs.Count == 0)
return null;
for (int i = 0; i < childs.Count; i++)
{
Row r = FindRow(root_row.ChildRowByIndex(i), item);
if (r != null)
return r;
}
return null;
} |
|
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Oct 28, 2005 10:54 pm Post subject: |
|
|
Yes - but its expensive because it requires a full depthwise search of the tree. The VirtualTree method uses the Parent property to construct a "path" to the given item from the root row. It then uses the IndexOf method of the child object collection to locate the index of each item within its parent. If IndexOf is implemented as a simple linear search then this will perform the same as your method. But many collections implement a more efficient algorithm for IndexOf (by indexing items using some form of Hashtable) allowing the location algorithm to be much more efficient. _________________ Infralution Support |
|
Back to top |
|
|
|