【问题标题】:c# winform , How to fitch or how to get usersId from Groupc# winform , 如何匹配或如何从 Group 中获取 usersId
【发布时间】: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


    【解决方案1】:

    我不确定,但如果你这样做,你会得到什么?

        int[] PatiendIds;
    //then in your select new 
        select new {u.DOB, u.PatientId}).Distinct().ToListAsync();
         PatiendIds = result.Select(x => x.u.PatientId).ToArray(); 
    

    【讨论】:

    • 感谢您的回复,但这会为我提供 datagridView 中的所有患者 ID。假设第一排是 40 岁的患者,第二排是 30 岁的患者,依此类推。然后,当我单击 40 岁组的第一行时,我想获取他们的患者 ID。我的意思是我只想要选定的行 PatientId,yma 很多,所以我想获取他们的 id。再次感谢您
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多