【问题标题】:how can i show my list in drop down list in c#?如何在 C# 的下拉列表中显示我的列表?
【发布时间】:2014-12-01 07:17:57
【问题描述】:
我的程序中有一个对象列表。
List<Table> Tables;
我有一个下拉框tableList
我想在下拉框中显示此列表。使用
tableList.Items.AddRange(Tables);
给我错误。这不是正确的方法吗?请帮忙。
【问题讨论】:
标签:
c#
list
drop-down-menu
collections
【解决方案1】:
试试这个:
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 列表已填满,并且您的 Table 类中有 Index 属性。
【解决方案2】:
您需要指定要在下拉列表中显示的 Tables 类的属性。如果您只是通过 List 下拉框无法理解究竟要显示什么。您需要为下拉/组合框指定选项、选定值和索引。