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 

Single table NodeID ParentNodeID
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
slickompressor
Guest





PostPosted: Tue Nov 29, 2005 9:24 pm    Post subject: Single table NodeID ParentNodeID Reply with quote

I have a single table with a NodeID, ParentNodeID that I create a Dataset with in Visual Studio 2003. I then generate a dataset and set it as the datasource for the Virtual Tree control. Currently it is populating all records from my table into the same level. What do I need to do to get the Virtual Tree to recognize the relationship within a single table?
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Nov 30, 2005 8:24 am    Post subject: Reply with quote

There are two things that you need to do.

First create a relationship in your dataset using Visual Studios dataset editor between the ParentNodeID and the NodeID. This will allow you to set the VirtualTree RowBinding ParentRelation and ChildRelation properties. Now when you run the project, rows that have children can now be expanded to show the children.

To prevent all the nodes in the table being shown at the top level you need to create a DataView for the table and set the RowFilter to "ParentNodeID = 0". Then set this DataView as the DataSource for the Virtual Tree. You can either do this programmatically in your constructor following the call to InitializeComponent() eg

Code:
DataView dataView = new DataView(_dataSet.Nodes, "ParentNodeID = 0", "", DataViewRowState.Unchanged);
_virtualTree.DataSource = dataView;


Or you can create the DataView and assign the DataSource in the form designer. If you do this you need to ensure that designer generated code calls EndInit for the DataView before calling EndInit for VirtualTree eg

Code:
((System.ComponentModel.ISupportInitialize)(this._dataSet)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this._virtualTree)).EndInit();


otherwise the DataView will not be fully constructed at the time VirtualTree attempts to bind to it. We are looking at a fix so that this order does not matter.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
slickompressor
Guest





PostPosted: Thu Dec 08, 2005 10:56 pm    Post subject: Reply with quote

Thanks for the quick response. I'll let you know what happens.
Back to top
Guest






PostPosted: Wed Jun 28, 2006 8:43 am    Post subject: Reply with quote

Is it posible to use DataSource insted DataView
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jun 28, 2006 9:14 am    Post subject: Reply with quote

I'm not sure what you are asking? If you want to bind to a recursive data table (as the original poster asked) then you have to set the DataSource to a data view which selects just the root node. Otherwise you will get all rows in the table displayed. If your table does not have recursive parent/child relationships then of course you can just set the DataSource to a DataTable of the DataSet.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
macu



Joined: 06 Jun 2006
Posts: 12

PostPosted: Wed Jun 28, 2006 9:39 am    Post subject: Reply with quote

OH Sorry not DataSource but BindingSource. My mistake Very Happy
Back to top
View user's profile Send private message
macu



Joined: 06 Jun 2006
Posts: 12

PostPosted: Wed Jun 28, 2006 10:12 am    Post subject: Reply with quote

Maby I describe the problem . I have table “Folders” (PK ID) and in this table I have a column (SubID) Relation look like this .
Folder(Pk ID) -> Folder(SubID).
I Created dataview
Code:

data = new DataView(this.dataSet11.Tables["Folder"], "SubID = 0", "", DataViewRowState.Unchanged);
            this.virtualTree1.DataSource = data;

but it dosn`t work . I got planty of errors especialy concerning filter . Can you help ??
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jun 28, 2006 10:37 pm    Post subject: Reply with quote

You can set the DataSource to a BindingSource - but I don't see how this will help in this case. You haven't really given me enough information to be able to determine what the problem is. What are the errors that you are getting?

It may be better if you email a sample project illustrating your problem to support@infralution.com - or if you just want to know how to set up a recursive relationship then we can send you a sample project if you provide an email address.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
macu



Joined: 06 Jun 2006
Posts: 12

PostPosted: Mon Jul 03, 2006 1:49 pm    Post subject: Reply with quote

I have created a treeview which displays this relation correctly but other problem occurred . When I use bindingContext or dataView to add Item I got an exception. Is there another way to add a row to a treeview ?? . I also noticed that in sample you send me when you drag an item on itself it disappear. Could you send me a sample that will handle simple operations (Adding , Deleting ) and without row disappearing. I am new in using your tree so I apologies if I make to much trouble . Best regards

Code:

private void asdToolStripMenuItem_Click(object sender, EventArgs e)
        {
           this.BindingContext[this.dataView].AddNew();
        }


Code:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="Infralution.Controls.VirtualTree"
  StackTrace:
       at Infralution.Controls.VirtualTree.DataRowRowBinding.GetChildrenForRow(Row row)
       at Infralution.Controls.VirtualTree.VirtualTree.GetChildrenForRow(Row row)
       at Infralution.Controls.VirtualTree.Row.LoadChildItems()
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jul 05, 2006 1:10 am    Post subject: Reply with quote

The problem is that your code adding a node is not adding a fully populated node. The following code adds a child node to the currently selected node:

Code:
private void _addButton_Click(object sender, System.EventArgs e)
{
    ItemDataSet._ItemRow parentItem = virtualTree.SelectedItem as ItemDataSet._ItemRow;
    if (parentItem != null)
    {
        itemDataSet._Item.Add_ItemRow(parentItem, "New Child");
    }
}


Even given your incorrect code you should not probably get the exception you did - so we will take a look at that for the next release.

The drag and drop onto a child issue is one that we fixed when using object binding - but it has obviously been overlooked for recursive dataset bindings. You can work around this in the current release by handling the GetRowDropLocations event and checking for this condition. The following code prevents dropping a row onto itself (and so causing it to dissappear)

Code:
private void virtualTree_GetAllowedRowDropLocations(object sender, GetAllowedRowDropLocationsEventArgs e)
{
    // get the default drop locations
    //
    RowBinding binding = virtualTree.GetBindingForRow(e.Row);
    e.AllowedDropLocations = binding.GetAllowedDropLocations(e.Row, e.Data);

    // check that we aren't dropping a row on itself or it's descendant
    //
    Row[] dropRows = (Row[])e.Data.GetData(typeof(Row[]));
    if (dropRows != null)
    {
        foreach (Row dropRow in dropRows)
        {
            if (e.Row == dropRow || e.Row.IsDescendant(dropRow))
            {
                e.AllowedDropLocations = RowDropLocation.None;
            }
        }
    }       
}


We will fix the DataSet bindings in the next release of both Version 2.5 and 3 of Virtual Tree so that this workaround is not required.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
macu



Joined: 06 Jun 2006
Posts: 12

PostPosted: Wed Jul 05, 2006 8:36 am    Post subject: Reply with quote

Thank you for your support . However the problem is more complex . In my program not only I want to add childes to my parent row but root rows too . Is it possible to add root without throwing the exception ?? Could you tell me approximate time when you will issue the next release because I have limited time to finish my project and the tree is most important thing in it. Best regards.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jul 05, 2006 9:23 am    Post subject: Reply with quote

The following code adds a root row:

Code:
ItemDataSet._ItemRow newItem = itemDataSet._Item.New_ItemRow();
 newItem.Text = "Root";
 itemDataSet._Item.Add_ItemRow(newItem);
 virtualTree.UpdateRows(true);


Note that with the current release this does cause the same internal exception as you were getting earlier (which will show up in the debugger) but in this case the exception is handled and provided you call UpdateRows following everything works OK.

We should have release that fixes these issues within about a week. Have you purchased Virtual Tree - if so we could potentially release even sooner if your deadline required it.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Wed Jul 05, 2006 10:22 am    Post subject: Reply with quote

Week is ok Very Happy . The code works but when you click added row it generates new exception .

Code:

//-----------this works :D----------------
private void asd2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
 ItemDataSet._ItemRow newItem =     itemDataSet._Item.New_ItemRow();
            newItem.Text = "Root";
            itemDataSet._Item.Add_ItemRow(newItem);
            virtualTree.UpdateRows(true);
            }
            catch (Exception ex) { }
        }




Code:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="Infralution.Controls.VirtualTree"
  StackTrace:
       at Infralution.Controls.VirtualTree.DataRowRowBinding.GetChildrenForRow(Row row)
       at Infralution.Controls.VirtualTree.VirtualTree.GetChildrenForRow(Row row)



[/code]
I can wait until u fix this so you don’t need to hurry

I am working on a big project and if make your tree working I will buy a license for it .
Back to top
macu



Joined: 06 Jun 2006
Posts: 12

PostPosted: Wed Jul 05, 2006 10:24 am    Post subject: Reply with quote

this post was mine Very Happy
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jul 07, 2006 1:51 am    Post subject: Reply with quote

We've done some investigation of the issue. The problem arises because Virtual Tree, in this case, is notified of the ListChanged event before the DataView that it is bound to is updated to include a DataRowView for the new DataRow.

You can avoid this issue in the current release by using SuspendDataUpdate and ResumeDataUpdate as follows:

Code:
virtualTree.SuspendDataUpdate();
ItemDataSet._ItemRow newItem = itemDataSet._Item.New_ItemRow();
newItem.Text = "Root";
itemDataSet._Item.Add_ItemRow(newItem);
virtualTree.ResumeDataUpdate();


We will change the code so that you don't get a NullReferenceException if you don't do this - but even with the change you will still need to use Suspend/ResumeDataUpdate (or call virtualTree.UpdateRows()) for virtual tree to behave correctly.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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