Hi there.
I have a GanttView bound to a BusinessObject. It has been working fine but only now I noticed it will throw an exception if a root-level task is deleted. Once the root-level task is deleted, the GanttView will delete the root-level and all tasks that belong to the root-level tasks collection in the viewer, but in the underlying datatable, only the root-level task row will be deleted. Once the user saves his work and afterwards gets back to the same project, the GanttView won't find the root-level row for the tasks that were left orfans in the database, which will throw an exception.
Thinking this could be a BusinessObject problem, I wrote the same program using a regular dataset in the same way the documentation shows it as a sample. The children rows in the dataset won't be deleted either.
Could you guys think of a workarong for this?
Thanks in advance.
Ivan
PS: I went ahead and built a sample using the same code provided on the help file ( http://help.infragistics.com/NetAdvantage/WinForms/2011.1/CLR2.0/?page=WinGanttView_DataBinding_Support_for_WinGanttView.html ) and attached to this post. You can delete a sub-task and check the grid to see that it works fine. But then go and delete a root-level task and then the grid will show that only the root-level row was deleted from the table, although the GanttView won't show them anymore. Then, just click the Requery button and you will get the error.
Hi Georgi.
Unfortunatelly this will produce yet another issue...
OK, you go and CLEAR the subtasks once a task is deleted. Now, with the change you suggested, using the same sample I have posted, go on, move a root task to be a child of its above task and then delete this same root task you have just moved... there will be sub-tasks left orfans. Yeah, I know, this wouldn't happen a lot on the field, but it can, and I am just trying to avoid know errors in the application.
The only effective way I have found so far is to disable DELETING if the task being deleted has children tasks.
It looks like this control needs some review from the authors...
Thanks for your attention so far.
Hello Ivan,
Maybe one possible approach for this scenario is to handle UltraGanttView1_TaskDeleting() event and include the code: e.Task.Tasks.Clear(). If you have a deeper structure from ParentTask->ChildTasks->ChildChildTasks and ect., my suggestion is to call in this event your recursive method which will clear the children of your current task (from TaskCollection)
Please let me know if you have any questions.
Regards
Hi again Georgi.
I think I spoke too soon. :-)
Although this will solve the "Delete Root-Level" thing, it will create another issue, since the GanttView automatically deletes its row whenever it is moved as a sub-task of its above task. So, if the user moves a Root-Level Task to be a sub-task of its above one, this current row will be deleted, and sub-sequently will lose all its subtasks, which shouldn't be deleted, really, they should be moved along with their parent-task.
You can test this with the sample you sent me.
So, I am back to square one.
Thanks for your reply.
Well... that will do it. Thank you.
Thank you very much for attached sample. I saw the mentioned behavior and I think it is expected . Maybe one possible approach to solve this issue is to add a Relation with Constraints. For example:
Dim dr As New DataRelation("RR", theTasks.Columns("TaskID"), theTasks.Columns("ParentTaskID"), True) theDataSet.Relations.Add(dr) theDataSet.EnforceConstraints = True
Dim dr As New DataRelation("RR", theTasks.Columns("TaskID"), theTasks.Columns("ParentTaskID"), True)
theDataSet.Relations.Add(dr)
theDataSet.EnforceConstraints = True
By this way when you delete your Main record, all child records also will be deleted. If you are using database, you could add this relation and Cascade constraints on database level and then this code is not necessary.
Please take a look at the modifications that I made In your sample and let me know if you have any questions.