我有以下代码来填充 DataGridView
var results = from loc in dtLocations.AsEnumerable()
join con in dtContacts.AsEnumerable() on (int)loc["contactid"] equals (int)con["id"]
select new
{
id = con["id"],
mpoc = loc["mpoc"],
directno = loc["directno"],
extension = loc["extension"],
faxno = loc["faxno"],
billing = con["billing"],
fullname = con["fullname"],
mobno = con["mobno"],
email = con["email"]
};
dgv.AutoGenerateColumns = false;
dgv.DataSource = results.ToList<object>();
但是当我单击一个单元格时,我无法将其读回
private void dgvLocations_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = sender as DataGridView;
????? vals = ((List<object>)dgv.DataSource)[e.RowIndex];
object id = vals.id; //errors of course
}
我可以在 Visual Studio 的 Watcher 面板中看到它可以确定列表中的元素,但我无法弄清楚我需要将 vals 设置为哪种类型才能再次读取它们:(