Visualizer : WorkItemHelper problem

Oct 25, 2007 at 11:37 AM
Hi.

Thank you for the smart client contrib, it help me very much.

I had a problem with the WpfVisualizer.
WorkItem hierarchy was not correctly reprenseted. I corrected the problem in WorkItemHelper class in method : "TreeViewItem GetTreeViewItem(object item, ItemCollection nodes, bool getWorkItemsNode)" .

getWorkItemsNode must be set to "false" when the method is called by itself.

I replaced :

if (tempNode == null)
{
foreach (TreeViewItem node in nodes)
{
TreeViewItem itemNode = GetTreeViewItem(item, node.Items, getWorkItemsNode);
if (itemNode != null)
tempNode = itemNode;
}
}

by :
if (tempNode == null)
{
foreach (TreeViewItem node in nodes)
{
TreeViewItem itemNode = GetTreeViewItem(item, node.Items, false);
if (itemNode != null)
tempNode = itemNode;
}
}

It is correct ?

Thanks.

Alexandre


Sorry for my bad english...
Jan 22, 2008 at 10:56 AM
Hi Alexandre,

I've just been having a similar problem (almost 3 months later!) and didn't spot your post until I had implemented my own fix.

I agree that the problem only occured when adding work items ('getWorkItemsNode' is true) but fixed it in a slightly different way.

Instead of always setting the 'getWorkItemsNode' to false when performing the recursive call I updated the method so that the recursive
call was the last thing to happen. I think this may be a slightly clearer update (in my opinion at least). I also added 'break' statements
within the 'foreach' blocks to terminate the loop at the earliest possible moment.

Here's my updated method (altered section in bold):

private TreeViewItem GetTreeViewItem(object item, ItemCollection nodes, bool getWorkItemsNode)
{
TreeViewItem tempNode = null;

if (item == null)
return null;

if (nodes == null)
return null;

foreach (TreeViewItem node in nodes)
{
if ( node != null && node.Tag == item )
{
tempNode = node;
break;
}
}

if (tempNode != null)
{
if ( getWorkItemsNode && !tempNode.Items.IsEmpty )
{
tempNode = tempNode.Items(0) as TreeViewItem; // note: had to use parentheses instead of indexer syntax - thank you Wiki :)
}
}
else
{
foreach (TreeViewItem node in nodes)
{
TreeViewItem itemNode = GetTreeViewItem(item, node.Items, getWorkItemsNode);

if ( itemNode != null )
{
tempNode = itemNode;
break;
}
}
}
return tempNode;
}

I am going to raise this as an issue to get a fix included in the download so others don't have to suffer as we did :D.