private void RemoveDataSourcesExcept(TreeNodeCollection nodes, DataSourceBase value) { for (int i = 0; i < nodes.Count; i++) { TreeNode node = nodes[i]; if (node.Tag == value || value.HasParent(node.Tag as Base)) { node.Expand(); continue; } if (node.Tag is DataConnectionBase) { RemoveDataSourcesExcept(node.Nodes, value); } else { node.Remove(); i--; } } }