开发者

Assigning each property of every single item of IEnumerable Collection to different textboxes

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 o开发者_Go百科f an item to this


Why would you need a lambda?

var itemSource = enumerable.toList();
textbox1.text = itemSource[0].toString();
textbox2.text = itemSource[1].toString();


textbox1.Text = enumerable.First();
textbox2.Text = enumerable.Skip(1).First();


Yet another way to skin this cat:

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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜