Filter task list

W

Wayne

Hello all,

Can anyone assist with the best way to filter a list of tasks
programmtically? I am using the following code in a c# add-in for Projects
2007 but would like to apply a filter prior to the foreach statement so only
tasks containing the text 'design' in the Name field are included:

foreach (MSProject.Task MSPTask in MSPApp.ActiveProject.Tasks)
{
//
}

I can use if statements within the loop but this seems quite inefficient -
how do you apply a filter or select statement to a list of tasks prior to
looping through?

Thanks
Wayne
 
J

John

Wayne said:
Hello all,

Can anyone assist with the best way to filter a list of tasks
programmtically? I am using the following code in a c# add-in for Projects
2007 but would like to apply a filter prior to the foreach statement so only
tasks containing the text 'design' in the Name field are included:

foreach (MSProject.Task MSPTask in MSPApp.ActiveProject.Tasks)
{
//
}

I can use if statements within the loop but this seems quite inefficient -
how do you apply a filter or select statement to a list of tasks prior to
looping through?

Thanks
Wayne

Wayne,
I'm not sure how it would look in C# but try the FilterEdit Method
followed by the FilterApply Method. I use both of those frequently in my
VBA macros when I want to limit processing to a selected group of tasks.

Hope this helps.

John
Project MVP
 
J

John

John said:
Wayne,
I'm not sure how it would look in C# but try the FilterEdit Method
followed by the FilterApply Method. I use both of those frequently in my
VBA macros when I want to limit processing to a selected group of tasks.

Hope this helps.

John
Project MVP

Wayne,
By the way, I forgot to mention that a filter is unique to a view and
you will need to run your For Each loop on the ActiveSelection.Tasks
instead of on ActiveProject.Tasks.

John
 
J

Jack Dahlgren MVP

You can filter using filteredit then filterapply then selectall, but really
the easiest and most robust way is to just use an if statement.
I'd hardly consider it to be inefficient.

if instr(task.name, "design") > 0 then...
'do stuff
end if

-Jack Dahlgren
 
W

Wayne

Thanks guys for your responses, currently my addin takes approx 30sec to loop
over around 500 task lines - some of the projects this addin will be used on
may contain over 4000 task lines of which only 10-20 may be selected for
processing so assessing each line with an if statement will seem to take an
unnecessarily long period of time for a small selection.

The filter\Selectall methods will work but are a little untidy - the
selectall method leaves all records highlighted while the process executes. I
was hoping to use either a LINQ or DASL query but have found no documentation
or examples for MSProject and I'm not sure if either are even supported? Is
OLE DB an option?

Thanks again
Wayne
 
R

Rod Gill

OLEDB is no longer supported in Project 2007. If you have Project Server,
then simply search the Reporting Database. Otherwise you either need to run
code to write to a database or continue as you are.

SelectBeginning will restore the first task only being selected.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top