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 

Drag first row to second row...

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



Joined: 19 Jan 2007
Posts: 44

PostPosted: Sun Jan 21, 2007 9:00 pm    Post subject: Drag first row to second row... Reply with quote

I am using runtime data binding, and I have a problem with drag drop

When my control receive virtualTree1_GetAllowRowDrag event, my program will call my system to raise DoDragDrop event (so the drag drop event does not actually from Virtual tree)... during dragging, my control will receive virtualTree1_GetAllowedRowDropLocations, virtualTree1_GetRowDropEffect... which are correct... but once my control receive virtualTree1_RowDrop event, my control will call my system to update the run-time data structure, then call virtualTree1.UpdateRows(); to update the tree...

But there is a problem, if I drag the first row (the RootRow is hidden) to the second row (I want to set first row as child row of the second row), then everything disappear, there is no any row display in the virtual tree... I notice after virtualTree1.UpdateRows(); the virtualTree1.ButtonRow.Item is null... how can I force virtual tree to reload all data from my run-time data list?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sun Jan 21, 2007 11:26 pm    Post subject: Reply with quote

This will be pretty hard to diagnose without some code. Can you maybe email us a zipped sample project which illustrates your problem. Also check out the Simple Tree sample - which implements Drag and Drop using object binding.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Wed Jan 24, 2007 8:46 pm    Post subject: Reply with quote

-RootRow (Car - hidden)
-FirstRow (Engine)
-SecondRow (Body)

When I tried to parent First Row to any other row, the entire tree is disappear... and the tree won't show any row anymore...
(no matter I tried to call UpdateRows, UpdateRowData... but the interesting thing is there is data inside the virtual tree

vitrualTree1.RootRow.Item.Name == Car

vitrualTree1.RootRow.ChildItems[0].Name == Body

vitrualTree1.RootRow.ChildItems[0].Children[0].Name == Engine

as you can see, the firstRow has been parenting to the secondRow inside the VirtualTree... but why there is no any row display in the UI?

)
the problem is only happened on the "FirstRow" parenting to other row

But if the tree setting as ShowRootRow = true, there is no problem with parenting the first row

I tried to create some test data by using SimpleTree example, but there is no problem with it...


Code:
private void _virtualTree_GetAllowRowDrag(object sender, GetAllowRowDragEventArgs e)
      {
         this.DoDragDrop(e.Row.Item, DragDropEffects.Move);
         e.AllowDrag = true;
      }

      private void _virtualTree_GetAllowedRowDropLocations(object sender, GetAllowedRowDropLocationsEventArgs e)
      {
         e.AllowedDropLocations = RowDropLocation.OnRow;
      }

      private void _virtualTree_GetRowDropEffect(object sender, GetRowDropEffectEventArgs e)
      {
         e.DropEffect = DragDropEffects.Move;
      }

      private void _virtualTree_RowDrop(object sender, RowDropEventArgs e)
      {
         Part dragPart = e.Data.GetData(typeof(Part)) as Part;
         if(dragPart != null)
         {
            (e.Row.Item as Part).AddChild(dragPart);
            _virtualTree.UpdateRows();
         }
      }



My data structure is simple as Parts, only thing is I have to ask my data base for all informations

Code:

public class VTNode
   {
      protected MyDatabase m_container;
      protected string m_uid;

      public VTNode Parent
      {
         get
         {
            return m_container.GetParent(m_uid);
         }
      }

      public IList Children
      {
         get
         {
            return m_container.GetChildren(m_uid)
         }
      }

      public virtual string Name
      {
         get
         {
            return m_container.GetNodeName(m_uid);
         }         
      }

      public string Uid
      {
         get { return this.m_uid; }
         set { this.m_uid = value; }
      }

      public VTNode(MyDatabase container, string uid)
      {
         m_container = container;
         m_uid = uid;
      }


Please given me some suggestions where I should look into this bug... and please provide me a list of events after UpdateRows(true) has been called...

Thanks


[/code]
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Wed Jan 24, 2007 8:48 pm    Post subject: Reply with quote

Original data:

-RootRow (Car - hidden)
---FirstRow (Engine)
---SecondRow (Body)

Trying to do this:
-RootRow (Car - hidden)
---SecondRow (Body)
------FirstRow (Engine)
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Wed Jan 24, 2007 8:56 pm    Post subject: Reply with quote

Note:
I also register GetRowData event to provide icon for the row
Code:
private void virtualTree1_GetRowData(object sender, Infralution.Controls.VirtualTree.GetRowDataEventArgs e)
{
      e.RowData.Icon = GetIcon(e);
}
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jan 24, 2007 9:57 pm    Post subject: Reply with quote

I think I see your problem. You are implementing the drag and drop methods/events programmatically (not using the default ObjectBinding methods) and it looks like you are attempting to drag the FirstRow (Engine) onto one of its child rows SecondRow (Body).

The ObjectBinding implementation of drag and drop (which the Simple Tree sample project uses) explicity prevents you dropping a parent onto one of its children or descendants. The reason is that this is ill defined and if you allow it to happen you create a loop where the child is eventually parented by itself - but since a child can only have one parent this disconnects it from the main tree (meaning the data source no longer has any children).

If what you want to do is swap the two items in the hierarchy (not really move the selected node and its children) you will have to handle this somewhat differently.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Wed Jan 24, 2007 9:58 pm    Post subject: Reply with quote

more info - same issue...

-RootRow (Car - hidden)
---FirstRow (Engine)
---SecondRow (Body)


Code:
void virtualTree1_OnVtKeyDown(object sender, KeyEventArgs e)
{
   if (e.KeyCode == Keys.Delete)
   {
       MyDataBase.RemoveCurrentSelectedRows();
       virtualTree1.UpdateRows(true);
   }
}


if I try to remove the FirstRow (Engine), entire tree disappear ... I have to reboot my application
(same as drag FirstRow to SecondRow, there is no any row on the UI, but from debugging, the row item was inside the tree...

vitrualTree1.RootRow.Item.Name == Car

vitrualTree1.RootRow.ChildItems[0].Name == Body
)
Again, this problem only happened on removing FirstRow...

Please let me know what information I should check or which events I need to register...

One more question... why UpdateRows will reset SelectedItems to null?

Thanks
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Wed Jan 24, 2007 10:01 pm    Post subject: Reply with quote

-RootRow (Car - hidden)
---FirstRow (Engine)
---SecondRow (Body)

Engine and Body are in the same level (under RootRow), I am not trying to drag a row to it's own child
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Wed Jan 24, 2007 10:38 pm    Post subject: Reply with quote

The DataSource still contains correct information when all rows has been disappear...

but there is something strange...

-RootRow (Car - hidden) <-- level 0
---FirstRow (Engine) <-- level 1
---SecondRow (Body) <-- level 1

In SimpleTree (which works correctly), I tried to drag Engine to Body

Code:
private void _virtualTree_RowDrop(object sender, RowDropEventArgs e)
      {
         Part dragPart = e.Data.GetData(typeof(Part)) as Part;
         if(dragPart != null)
         {
            (e.Row.Item as Part).AddChild(dragPart);
            _virtualTree.UpdateRows();
         }
      }



after database has been update, I raised _virtualTree.UpdateRows(); --> then virtualTree called Car.Children (IList) property --> called _virtualTree_SelectionChanged ... [this._virtualTree.SelectedItem now become null] --> called Body.Children (IList) property --> called _virtualTree_GetRowData ( e contains "Body" row) --> called Body.Name --> done...

the result
-RootRow (Car - hidden) <-- level 0
---SecondRow (Body) <-- level 1
----------FirstRow (Engine) <-- level 2


But in my application, I tried to do the same thing, but

after database has been update, I raised _virtualTree.UpdateRows(); --> then virtualTree called Car.Children (IList) property --> called _virtualTree_SelectionChanged ... [this._virtualTree.SelectedItem now become null] --> done...

As you can see I miss
--> called Body.Children (IList) property --> called _virtualTree_GetRowData ( e contains "Body" row) --> called Body.Name

what issues costs this bug?
Thanks,
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Jan 25, 2007 7:29 am    Post subject: Reply with quote

I'm not sure I fully understand what you are asking - but I'll attempt to answer. When UpdateRows is called (either by you directly or as a result of drag/drop) VirtualTree calls the DataSource to get the child lists again (via the GetChildren event/method) for each row and updates it visual representation.

Virtual Tree identifies rows by the domain Item associated with a row (ie the items return by GetChildren). If you create new items each time the GetChildren method/event (or the object property that returns the children) is called then these objects will not match the existing items in the tree. Since the (old) selected items are no longer in the tree the selection becomes empty.

There are two ways of handling this. One is to ensure that you return the existing items where possible. You can do this in your application code by maintaining the objects in list or hash table where your can retrieve the existing object if there is one.

The second mechanism is to override the Equals and GetHashCode operators for your class so that objects that represent the same underlying object are treated as equal. This solution can be dangerous however because it allows for aliasing where you have two objects with different values that are seen by the system as the same object. In general it is better to implement a mechanism in your application code that ensures that you don't create duplicate objects.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Fri Jan 26, 2007 4:54 am    Post subject: Reply with quote

Thanks ... but I still need more help

I do have a hash table to keep all row items...

same story... RootRow (Car - hidden)
-FirstRow (Engine) <--- level 1
-SecondRow (Body) <--- level 1

I am dragging Engine to Body, and expect tree like this

-SecondRow (Body) <--- level 1 (collapsed, but has a child - Engine)
-----FirstRow (Engine) <--- level 2

but I got an empty tree

Here is the insteresting part...
(1)
if I do like this

Code:
Init()
{
   ...
   virtualTree1.ShowRootRow = true;
   ...
}

virtualTree1_OnVtGetAllowRowDrag(object sender, GetAllowRowDragEventArgs e)
{
...
otherControl.DoDragDrop(...)
virtualTree1.ShowRootRow = true;
virtualTree1.UpdateRows(reloadChildren);
virtualTree1.ShowRootRow = false;
}


I GOT THE CORRECT RESULT

-SecondRow (Body) <--- level 1 (collapsed, but has a child - Engine)
-----FirstRow (Engine) <--- level 2

(2)
if I keep the original way
Code:
Init()
{
   ...
   virtualTree1.ShowRootRow = true;
   ...
}

virtualTree1_OnVtGetAllowRowDrag(object sender, GetAllowRowDragEventArgs e)
{
...
otherControl.DoDragDrop(...)
virtualTree1.UpdateRows(reloadChildren);
}


I got an empty tree... but if I use mouse to click on the position where the "Body" row suppose to be (blank line, first row position...) ... the tree row is appear with correct layout

-SecondRow (Body) <--- level 1 (collapsed, but has a child - Engine)
-----FirstRow (Engine) <--- level 2


looks like some row widgets were hidden or did not update ...

(I did not override the VirtualTree and any widget)

Please provide me some more supporting... this bug is taking too long for me... thanks
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Fri Jan 26, 2007 4:57 am    Post subject: Reply with quote

sorry... mistake

Code:
Init()
{
   ...
   virtualTree1.ShowRootRow = false;
   ...
}


In init, I always set ShowRootRow as false.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jan 26, 2007 5:01 am    Post subject: Reply with quote

We can't really debug an issue in your software without actually having the code. If you can replicate the issue in a sample project that you can send zipped to us (at support@infralution.com) then we are happy to help. From your previous posts it appears that you can't actually get the problem to occur in the sample projects - which would seem to point to an application programming problem.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Sun Jan 28, 2007 11:46 pm    Post subject: Reply with quote

I have sent a sample code to support@infralution.com, could you please help me to debug it. Thanks
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Mon Jan 29, 2007 10:24 pm    Post subject: Reply with quote

Thanks for the help... the problem has been solved... Very Happy
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