LINQ结果(多列)绑定到comboBox,然后只为SelectedValue获取一列

时间:2018-11-15 06:37:48

标签: c# linq

我有一个LINQ来检索StationID和名称以绑定到comboBox,

var stationId = stationBll
  .GetStations(true)
  .Select(t => new { 
     StationID = t.StationID, 
     Name = t.Name })
  .ToList();

cbMachine.DataSource = stationId;
cbMachine.DisplayMember = "Name";
cbMachine.ValueMember = "StationID";

因此,当我想从selectedValue()获取ID时,它将分配整个内容,例如{StationID:1,名称:xxxxxx} 如何仅获取StationID,而不能获取全部内容? 请看附件图片,谢谢!

var StationId = cbMachine.SelectedValue;

enter image description here

0 个答案:

没有答案