C#:从列表填充ListBox的最简单方法 [英] C#: easiest way to populate a ListBox from a List

查看:392
本文介绍了C#:从列表填充ListBox的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个字符串列表,例如:

If I have a list of strings, eg:

List<string> MyList = new List<string>();
MyList.Add("HELLO");
MyList.Add("WORLD");

是否存在使用MyList的内容填充ListBox的简便方法?

Is there an easy way to populate a ListBox using the contents of MyList?

推荐答案

尝试:

List<string> MyList = new List<string>();
MyList.Add("HELLO");
MyList.Add("WORLD");

listBox1.DataSource = MyList;

看看 ListControl.DataSource属性

这篇关于C#:从列表填充ListBox的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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