Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#中的下拉列表中显示我的列表?_C#_List_Drop Down Menu_Collections - Fatal编程技术网

如何在c#中的下拉列表中显示我的列表?

如何在c#中的下拉列表中显示我的列表?,c#,list,drop-down-menu,collections,C#,List,Drop Down Menu,Collections,我的程序中有一个对象列表 List<Table> Tables; 列表表; 我有一个下拉框tableList 我想在下拉框中显示此列表。使用 tableList.Items.AddRange(表) 给了我错误。这不是正确的方法吗?请帮助。试试这个: List<Table> Tables = GetTables(); /* You should fill your list with a method */ tableList.Value

我的程序中有一个对象列表

List<Table> Tables;
列表表;
我有一个下拉框
tableList

我想在下拉框中显示此列表。使用

tableList.Items.AddRange(表)

给了我错误。这不是正确的方法吗?请帮助。

试试这个:

        List<Table> Tables = GetTables(); /* You should fill your list with a method */
        tableList.ValueMember = "Index";
        tableList.DisplayMember = "Name";   /* For example you have Name property that you want to show in combobox */
        tableList.DataSource = Tables;
List Tables=GetTables();/*你应该用一种方法来填写你的列表*/
tableList.ValueMember=“索引”;
tableList.DisplayMember=“名称”;/*例如,您有要在组合框中显示的Name属性*/
tableList.DataSource=表格;

我假设您的
表格
列表已填充,并且您的
表格
类中有
索引
属性。

您需要指定要在下拉列表中显示的来自表格类的属性是什么。如果您只是通过列表下拉框,则无法理解到底要显示什么。您需要为下拉框/组合框指定选项、选定值和索引。

如果您遇到错误,则您的问题需要明确说明该错误是什么。请参阅您正在查找的
数据绑定