views:

108

answers:

4

Elaboration of what I want to achieve :

I have an collection of an object in my itemsource.Suppose there are three items in my itemsource and i want each property of every single item to be assigned to different textboxes, how can i get this ?

textbox1.text = // assign the first value of an item to this

textbox2.text = // assign the second value of an item to this
+2  A: 
textbox1.Text = enumerable.First();
textbox2.Text = enumerable.Skip(1).First();
Femaref
I think you could also do. `enumerable.ElementAt(0)`, `enumerable.ElementAt(1)`, etc.
Jerod Houghtelling
Where's the lambda expression? ;)
LukeH
+3  A: 

Why would you need a lambda?

var itemSource = enumerable.toList();
textbox1.text = itemSource[0].toString();
textbox2.text = itemSource[1].toString();
jsmith
I agree, I also do not find using lambda suitable in this case.
VoodooChild
@jsmith As i was using the foreach loop earlier and i had to replace it with an better option so just knew that lambda expression would make it easier instead of getting looped the enumerable list again and again. tx for the answer. :)
Malcolm
A: 

You could put your text boxes into a list and step through both the items source and the text box list.

var textBoxes = new List<TextBox> { textbox1, textbox2 };
for( int index = 0; index < itemsSource.Count; index++ )
{
    textBoxes[index].Text = itemsSource[index].ToString();
}

I'm not sure what a lambda expression would do for you. Could you expand your question?

Jerod Houghtelling
A: 

Yet another way to skin this cat:

textbox1.Text = itemSource.ElementAtOrDefault(0);
textbox2.Text = itemSource.ElementAtOrDefault(1);
code4life