【发布时间】:2020-05-06 19:23:17
【问题描述】:
我正在显示有多少患者患有特定疾病并按年龄分组。我正在使用 CalculateAge 函数计算他们的年龄 假设 40 岁的人有 10 个患有特定疾病的人 30岁的人太多了……50岁的人太多了……等等。你明白了。 我的代码可以正常工作。但我怎样才能得到他们的身份证?我的意思是如何通过单元格单击 datagridview 显示谁是那些喜欢他们的名字的人 如何获取或获取那些人的身份?通过一些我必须如何收集它们我的数组并在 datagridview ClickEvent 中使用它们?我在下一步显示每个患者时遇到问题 单击 datagridview 行时的名字和姓氏。 这是我按组年龄显示的代码,效果很好
var result = await(from u in db.Patient
join a in db.Analys on u.PatientId equals a.PatientId
where a.diseaseId == diseasId
select u.DOB).Distinct().ToListAsync();
var data = result
.GroupBy(x => CalculateAge(x.ToString()))
.Select(grp => new
{
Age = grp.Key,
Amount = grp.Count()
}).ToList();
dgvResult.DataSource = data;
但是这里我想详细展示那些人
private void dgvResult_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
// Here I can only catch age but this mean all patients whtin this age and will not be correct
int age = Convert.ToInt32(dgvResult.Rows[e.RowIndex].Cells[0].Value.ToString());
}
}
我希望你能得到这个想法,请帮忙。提前谢谢!
【问题讨论】:
标签: c# winforms linq datagridview