Access View outside loop

Access View outside loop

Kevin.Bell
Advisor Advisor
510 Views
2 Replies
Message 1 of 3

Access View outside loop

Kevin.Bell
Advisor
Advisor

Hi,

 

I have a list of views elements which I've obtained by using a FilteredElementCollector.

 

I now need to iterate through the list and select the one which matches the name I want.

 

The problem is that I can't take the view I want outside the For loop due to its scope.

 

Ordinarily, I would define the variable outside the loop, but I can't do this with the View class as it doesn't contain a constructor...

 

This is my code:

 

View selectedview = new View();

foreach (View f in allviewlist)

   {
   if (f.Name == "East")
      {
      selectedview = f;
      }
   }

The first line fails.

 

Whats the best way of accessing the 'selectedview'?

 

Thanks.

0 Likes
Accepted solutions (1)
511 Views
2 Replies
Replies (2)
Message 2 of 3

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

initialize selectedview this way:

 

View selectedview = null;

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 3

Kevin.Bell
Advisor
Advisor

That's great! Thanks.

 

I knew it would be something simple!

0 Likes