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 

FindRow with single table tree throws NullReferenceException

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



Joined: 31 Mar 2006
Posts: 13

PostPosted: Fri Apr 21, 2006 3:59 pm    Post subject: FindRow with single table tree throws NullReferenceException Reply with quote

I have a single table recursive tree that is displaying correctly in the VirtualTree control. In other words, I have a single table like this:
Code:

id  parent_id   name
1       null    Root
2         1     Child
3         2     Grandchild

I setup a DataRelation in the dataset and Parent and Child relations in the DataRowRowBinding.

When I call FindRow with a valid row in the tree, I get a NullReferenceException with the following stack trace:

Code:

at Infralution.Controls.VirtualTree.DataRowRowBinding.GetDataRowView(DataRow dataRow)
   at Infralution.Controls.VirtualTree.DataRowRowBinding.GetParentForItem(Object item)
   at Infralution.Controls.VirtualTree.VirtualTree.GetParentForItem(Object item)
   at Infralution.Controls.VirtualTree.VirtualTree.FindRow(Object item)


My guess is that this is happening because the parent of the root node is null and the VirtualTree code isn't checking for that null. With the single table recursive tree, the root node has to have a null parent_id to specify that it's the root.

Is there anything I can do to make this work? Is this a bug in VirtualTree?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sat Apr 22, 2006 7:49 am    Post subject: Reply with quote

You are right - there does seem to be an issue with using FindRow with recursive Data Set bindings. Fortunately you can work around the issue by handling the GetParent event yourself (or overriding the GetParentForItem method) as follows:

Code:

private void virtualTree_GetParent(object sender, Infralution.Controls.VirtualTree.GetParentEventArgs e)
{
    DataRowView drv = e.Item as DataRowView;
    if (drv != null)
    {
        DataRow parentRow = drv.Row.GetParentRow("ItemItem");
        if (parentRow == null)
            e.Parent = virtualTree.RootItem;
        else
            e.Parent = DataRowRowBinding.GetDataRowView(parentRow);
    }
}


Where "ItemItem" is then name of your parent-child relation. Note that VirtualTree binds to the DataRowView not the underlying Row hence the call to GetDataRowView(parentRow) which finds the DataRowView for the parent row.

This also revealed another issue. If you set the DataSource to a filtered DataView at design time then FindRow may still return null depending on the order that the designer generated code in InitializeComponent calls EndInit for the DataView and VirtualTree. This is related to an earlier issue (see http://www.infralution.com/phpBB2/viewtopic.php?t=233). For this reason I would probably recommend setting the Data Source programattically following the InitializeComponent at this stage.

We will fix the exception issue ASAP. The initialization ordering issue looks a little more difficult.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Apr 24, 2006 1:57 am    Post subject: Reply with quote

We've managed to fix both these issues in the latest release (V2.5.2) - which was just going into testing when we received your post.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
amsimmon



Joined: 31 Mar 2006
Posts: 13

PostPosted: Mon Apr 24, 2006 4:03 pm    Post subject: FindRow works now for recursive tree Reply with quote

I took the new code and it solves the problem. Everything works correctly the way I'd expect it to. Thanks for the quick response!

If anybody else is trying the same thing, here's my find code:

Code:

        private void findSPA_Click(object sender, EventArgs e)
        {
            DataRowView[] rows = _resultsDataView.FindRows(findText.Text);
            if ((rows != null) && (rows.Length > 0))
            {
                resultsTree.SelectedItem = rows[0];
            }
        }
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