【问题标题】:Retrieving selected row in dataGridView as an object将 dataGridView 中的选定行作为对象检索
【发布时间】:2013-11-10 01:01:30
【问题描述】:

我有这样的课:

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中的行时选择“选择”对象。我需要以某种方式检索 selected 对象 AdressBokPerson

【问题讨论】:

    标签: c# .net winforms datagridview


    【解决方案1】:

    您可以通过将 DataBoundItem 转换为指定类型来获取对象:

    AdressBokPerson currentObject = (AdressBokPerson)dataGridView1.CurrentRow.DataBoundItem;
    

    【讨论】:

    • 这是我在使用 DataGridViews 时一直在寻找的答案。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    相关资源
    最近更新 更多