c# – 将dataGridView中的所选行检索为对象
发布时间:2020-12-15 06:50:39 所属栏目:百科 来源:网络整理
导读:我有一个这样的课: public partial class AdressBokPerson { public long Session { get; set; } public string F?rnamn { get; set; } public string Efternamn { get; set; } public string Mail { get; set; } } 添加到列表中: private readonly ListAd
我有一个这样的课:
public partial class AdressBokPerson { public long Session { get; set; } public string F?rnamn { get; set; } public string Efternamn { get; set; } public string Mail { get; set; } } 添加到列表中: private readonly List<AdressBokPerson> _avp = new List<AdressBokPerson>(); 绑定到一个dataGridView像这样: dataGridView1.DataSource = _avp; 到现在为止还挺好. 这是我的问题: 当选择dataGridView中的一行时,如何查找“哪个”对象被选中.我需要以某种方式检索所选对象AdressBokPerson. 解决方法
通过将DataBoundItem转换为指定的类型来获取对象:
AdressBokPerson currentObject = (AdressBokPerson)dataGridView1.CurrentRow.DataBoundItem; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |