E-Bat
E-Bat

Reputation: 4892

Set property values within linq expressions

Having

Dim hiddens As List(Of Integer)) 

I want to do set Hidden properties of UltraGridRows using this list values as indexes:

hiddens.Select(Function(x) ultraGrid1.Rows(x).Hidden = True)

That line compiles and i get not runtime exception at all, but corrsponding rows are not hidden. Is this a valid way to set properties in expressions?

Upvotes: 0

Views: 102

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460058

Don't set properties with LINQ. Use loops if you want to modify something. Use LIN(Q) if you want to query something. So you could simply use a For Each(which i would use):

For Each index As Int32 In hiddens
    ultraGrid1.Rows(index).Hidden = True
Next

or use List.ForEach:

hiddens.ForEach(Function(index) ultraGrid1.Rows(index).Hidden = True)

Erip Lippert: "The purpose of an expression is to compute a value, not to cause a side effect. The purpose of a statement is to cause a side effect."

Note that your query does not even execute until you use aFor Eeach(or other method that does it implicitly like ToList). It's just the definition of a query.

Upvotes: 2

JC Ford
JC Ford

Reputation: 7066

Try this:

hiddens.ForEach(Function(x) ultraGrid1.Rows(x).Hidden = True)

Upvotes: 0

Related Questions