In a windows forms application, using C# I want to programmtically pass the SMO DependencyWalker a single object ( table, View, etc ), discover the dependencies related to that object and then load a WinForms TreeView with the results where the TreeView looks exactly like the TreeView within the SQL Server 2008 Management Studio "View Dependencies" dialog. An good example would be to view the dependencies of the "Employees" table in the Northwind database with Management Studio. I have used something like the below code snippett to get started :
UrnCollection col = new UrnCollection();
foreach (Table table in database.Tables) {
if(table.Name == "Employees")
col.Add(table.Urn);
}
DependencyTree tree = sp.DiscoverDependencies(col, DependencyType.Children);
DependencyWalker walker = new DependencyWalker(server);
DependencyCollection depends = walker.WalkDependencies(tree);
//Iterate over each table in DB in dependent order...
foreach (DependencyCollectionNode dcn in depends)
This does return me all the dependencies that I would need for my TreeView, but I am unable to see how to iterate the results of the "depends" object or any of the other associted SMO objects so that I would be able to load The TreeView Nodes in the correct order with the correct parent/child node relationships. Maybe I am going about this in the wrong way. Is there anyone out there that has been able to do something like this successfully?