是否可以将列表框数据源设置为List< Tuple< string,string,int>仅Item1? [英] Is it possible to set listbox datasource to List<Tuple<string, string, int>> Item1 only?
本文介绍了是否可以将列表框数据源设置为List< Tuple< string,string,int>仅Item1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
public static class GlobalVariables
{
public static List<Tuple<string, string, int>> PopFile;
}
我正在尝试将PopFile用作列表框的数据源
and I'm trying to use PopFile as a datasource to listbox
listBox1.DataSource = GlobalVariables.PopFile;
问题是,它显然将([string],[string],[int])添加到了列表框,但是我只想添加元组的第一项.有可能吗?
The problem is that it obviously adds ([string], [string], [int]) to the listbox but I want to add only the first items of tuples. Is that possible?
我可以使用
foreach (Tuple<string, string, int> i in GlobalVariables.PopFile)
{
listBox1.Items.Add(i.Item1);
}
但是我更喜欢.DataSource.
but I'd prefer .DataSource.
推荐答案
listBox1.DataSource = GlobalVariables.PopFile;
listBox1.DisplayMember = "Item1";
listBox1.ValueMember = "Item3"; // optional
https://msdn.microsoft.com /en-us/library/system.windows.forms.listcontrol.datasource
这篇关于是否可以将列表框数据源设置为List< Tuple< string,string,int>仅Item1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文