用数组中的项目填充列表框 [英] populate the listbox with items in array

查看:67
本文介绍了用数组中的项目填充列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在Silverlight中使用C#开发Windows Mobile 7应用程序.
我需要获取数组中所有的项,然后使用c#将它们输入到列表框中

我正在开发从Web服务中获取字符串的应用程序,该字符串存储在名为mygroup(在代码中指定)的数组中.我需要在列表框中显示它.

这是我的代码:

for(int i = 0; i < userDetails.GroupDetails.Count; i++)
            {
               mygroup[i]= userDetails.GroupDetails[i];
              // this.listBox1.ItemsSource = mygroup[i].GroupName;
         // MessageBox.Show(Convert.ToString(mygroup[i].GroupName));

            }



请帮帮我.

在此先谢谢您.
您可能想先学习Silverlight编程...

Silverlight [

在您的XAML和代码中,放入

this.listBox1.DataContext = collection;




注意:如果使用ObservableCollection,则Collection可能更适合,因此,如果以后在同一collection上添加元素,它将自动更新UI.

就是这样.


感谢您的答复.

"this.listBox1.DataContext = mygroup [i]"

它可以正常工作,但是在我的列表框中只有一个值(循环的最后一个值).它没有填充我的数据源"mygroup [i]"中的所有内容.


Hi Everyone,
I am developing windows mobile 7 application using c# in silverlight.
I need to take all the items I have in a array and input them into an listbox using c#

I am developing application that fetch the string from web service an stored in array named as mygroup(specified in the code).I need to display it in listbox.

here is my code:

for(int i = 0; i < userDetails.GroupDetails.Count; i++)
            {
               mygroup[i]= userDetails.GroupDetails[i];
              // this.listBox1.ItemsSource = mygroup[i].GroupName;
         // MessageBox.Show(Convert.ToString(mygroup[i].GroupName));

            }



Please Help me.

Thanks in Advance.

From the looks of your commented code, you don''t have an understanding of how Silverlight itemscontrols are used.

You may want to work on learning Silverlight programming first...

Silverlight[^]


Use

<ListBox ItemsSource="{Binding}" x:Name="listBox1" ></ListBox>

in your XAML and in your code, put

this.listBox1.DataContext = collection;




Note : Collection could be better suited if you use an ObservableCollection so that if you add up an element later on the same collection, it will update your UI automatically.

Thats all.


thanks all for your replies.

"this.listBox1.DataContext = mygroup[i]"

it works ,but am getting only single value(last value of the loop) in my list box.it''s not populating all the content from my data source "mygroup[i]".


这篇关于用数组中的项目填充列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆