Sort Child Tasks by ID?

Hi,

Anyone have any suggestions on how to sort child tasks by ID or by some extended attribute field.

(I need to align the tasks to a list of items in my application ... in MSP, I use the application.sort capability).

I'm getting my head around the Utilities. Maybe there could be an extra method for the ArrayUtils to Sort the array by a field? (a suggestion or thought). (or this could be added to the TaskUtils - however, I need to sort the Resources too.)

Currently, rather than using a number field, I'd like to just set the ID field and sort this to know that all of the items are in the ID order.

Any thoughts, examples or alternative approaches welcome!!

Regards, Bruce

You can sort child tasks by ID, after implementation of IComparable Interface. Here is the sample implementation of this interface.

public class ClsTask : IComparable

{

private Task tmpTSK;

public ClsTask(Task ttK)

{

tmpTSK = ttK;

}

public int myID

{

get { return tmpTSK.Id; }

}

public string tName

{

get { return tmpTSK.Name; }

}

public DateTime tStart

{

get { return tmpTSK.Start; }

}

int IComparable.CompareTo(object x)

{

ClsTask tsk = (ClsTask)x;

if (tsk.tmpTSK.Id > this.tmpTSK.Id)

return -1;

else if (tsk.tmpTSK.Id < this.tmpTSK.Id)

return +1;

else

return 0;

}

}

After the implementation, you can sort the child tasks by ID using Sort method of ArrayList containing child tasks elements. Here is the sample for that.

ArrayList arrChild = project.RootTask.Children;

ArrayList arrSort = new ArrayList();

//arrChild.Sort();

foreach( Task tsk in arrChild )

{

ClsTask testTask = new ClsTask(tsk);

arrSort.Add(testTask);

}

arrSort.Sort();

foreach( ClsTask cTSK in arrSort )

{

//string strTskName

//Task ttt = (Task)cTSK.n

int inttID = cTSK.myID;

string inttName = cTSK.tName;

string dtStart = cTSK.tStart.ToString();

}

Hi,

I really appreciate the code ... I'll translate to vb.net and give it a try. I did look at the icomparable interface, your example makes it much clearer how it works!!

Regards, Bruce