我必须给用户一个从项目列表中选择的选项,然后,在他们选择的单个项目上,我需要从该项目中获取 guid。这将从 Sql 表的 Linq 查询中填充。
我从这个开始:
private void PopulateGatewayList()
{
var gateways = from gw in _entities.Gateways
where gw.IsActive
select gw;
foreach (var gateway in gateways)
{
checkedListBox_Gateways.Items.Add(gateway.Name);
}
}
但是一旦他们检查了一些东西,我就无法抓住向导。
什么是给用户名称但给我 guid 的好方法?
** 回答 **
在 Michael Yoon 的帮助下,我做了以下事情:
private void PopulateGatewayList()
{
var gateways = from gw in _entities.Gateways
where gw.IsActive
select gw;
foreach (var gateway in gateways)
{
checkedListBox_Gateways.Items.Add(new ListItem(gateway.Name, gateway.GatewayId.ToString()));
//checkedListBox_Gateways.Items.Add(gateway.Name);
}
}
private void checkedListBox_Gateways_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (Object selecteditem in checkedListBox_Gateways.SelectedItems)
{
var strItem = selecteditem as ListItem;
Console.WriteLine("Selected: " + strItem.Value);
}
}