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

时间:2014-12-01 07:17:57

标签: c# list drop-down-menu collections

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

List<Table> Tables;

我有一个下拉框tableList

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

tableList.Items.AddRange(Tables);

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

2 个答案:

答案 0 :(得分:0)

试试这个:

        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;

我认为您的Tables列表已填写,Index课程中有Table个属性。

答案 1 :(得分:0)

您需要指定要在下拉列表中显示的Tables类的属性。如果你只是通过List下拉框就无法理解究竟要显示什么。您需要为下拉/组合框指定选项,选定值和索引。