【发布时间】:2015-06-30 17:26:07
【问题描述】:
所以我想使用一个函数为组合框加载数据源,该函数将需要加载的数据源的名称作为字符串接收,然后让它加载它但是我无法让它工作因为我认为程序只是试图加载变量名而不是它所代表的数据源。抱歉,如果措辞不好,希望我的代码能澄清我的意思。
这就是我现在的做法
bool TeamPlayers(string teamName, ComboBox team)//Makes the players of the selected team available for selection as scorers
{
if (teamName == "Canada")
{
string[] players = {"Johny Moonlight", "DTH Van Der Merwe", "Phil Mackenzie" };
team.DataSource = players;
}
else if (teamName == "New Zealand")
{
string[] players = {"Dan Carter", "Richie Mccaw", "Julian Savea" };
team.DataSource = players;
}
else if (teamName == "South Africa")
{
string[] players = {"Jean de Villiers", "Bryan Habana", "Morne Steyn" };
team.DataSource = players;
}
return (true);
}
但我想做更多这样的事情
bool TeamPlayers(string teamName, ComboBox team)//Makes the players of the selected team available for selection as scorers
{
string[] Canada = {"Johny Moonlight", "DTH Van Der Merwe", "Phil Mackenzie" };
string[] NZ = {"Dan Carter", "Richie Mccaw", "Julian Savea" };
string[] RSA = {"Jean de Villiers", "Bryan Habana", "Morne Steyn" };
team.DataSource = teamName;
return (true);
}
其中 teamName 将是 Canada、NZ 或 RSA。 有谁知道我可以这样做吗?
【问题讨论】:
标签: c# combobox datasource