Retrieving selected row in dataGridView as an object

Dimo

I have a class like this:

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; }
    }

Added to a list:

private readonly List<AdressBokPerson> _avp = new List<AdressBokPerson>();

With binding to a dataGridView like this:

dataGridView1.DataSource = _avp;

So far so good.

Here is my question:

How do I find out 'which' object is selected when a row in the dataGridView is selected. I need to retrieve the selected object AdressBokPerson somehow.

Rob

You get the object by casting the DataBoundItem to the specified type:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Retrieving selected row in dataGridView as an object

From Dev

Retrieving Selected Row/Cell Values in DataGridView From one form to another

From Dev

Datagridview how to cast selected row to custom object

From Dev

Datagridview how to cast selected row to custom object

From Dev

Scroll to Datagridview selected Row

From Dev

Scroll to Datagridview selected Row

From Dev

IndexedDB: limit selected fields of retrieving object

From Dev

vb.net datagridview not showing selected row

From Dev

DataGridView- How to jump to the selected row in search?

From Dev

DataGridView selected row to display in text boxes

From Dev

print selected row from datagridview Error

From Dev

How to check if have any row selected on DataGridView?

From Dev

how to delete selected row from datagridview

From Dev

How to delete selected row from datagridview and database?

From Dev

How to get the selected object from the DataGridView?

From Dev

Retrieving the object from a replicated row with Laravel/Eloquent

From Dev

DataGridView row text disappears on every row except the selected one

From Dev

How to delete last row in DataGridView and keep the row selected?

From Dev

DataGridView row text disappears on every row except the selected one

From Dev

When selecting all cells in a row of datagridview, set the row to selected as property

From Dev

When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

From Dev

When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

From Dev

Winforms - Position new form directly under Datagridview selected row of parent

From Dev

Datagridview correct row is selected but the arrow is still pointing at the first record

From Dev

Need to get the first cells of a selected row in datagridview before delete it

From Dev

C# DataGridView get selected row number Exception

From Dev

Trying to delete selected row from datagridview but it is deleting multiple rows

From Dev

How to change row color in datagridview after checkbox is selected

From Dev

How to update selected row in datagridview through textbox located on another form?

Related Related

  1. 1

    Retrieving selected row in dataGridView as an object

  2. 2

    Retrieving Selected Row/Cell Values in DataGridView From one form to another

  3. 3

    Datagridview how to cast selected row to custom object

  4. 4

    Datagridview how to cast selected row to custom object

  5. 5

    Scroll to Datagridview selected Row

  6. 6

    Scroll to Datagridview selected Row

  7. 7

    IndexedDB: limit selected fields of retrieving object

  8. 8

    vb.net datagridview not showing selected row

  9. 9

    DataGridView- How to jump to the selected row in search?

  10. 10

    DataGridView selected row to display in text boxes

  11. 11

    print selected row from datagridview Error

  12. 12

    How to check if have any row selected on DataGridView?

  13. 13

    how to delete selected row from datagridview

  14. 14

    How to delete selected row from datagridview and database?

  15. 15

    How to get the selected object from the DataGridView?

  16. 16

    Retrieving the object from a replicated row with Laravel/Eloquent

  17. 17

    DataGridView row text disappears on every row except the selected one

  18. 18

    How to delete last row in DataGridView and keep the row selected?

  19. 19

    DataGridView row text disappears on every row except the selected one

  20. 20

    When selecting all cells in a row of datagridview, set the row to selected as property

  21. 21

    When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

  22. 22

    When the last row in a DataGridView is selected, a value from the previous row is returned instead of from the selected row

  23. 23

    Winforms - Position new form directly under Datagridview selected row of parent

  24. 24

    Datagridview correct row is selected but the arrow is still pointing at the first record

  25. 25

    Need to get the first cells of a selected row in datagridview before delete it

  26. 26

    C# DataGridView get selected row number Exception

  27. 27

    Trying to delete selected row from datagridview but it is deleting multiple rows

  28. 28

    How to change row color in datagridview after checkbox is selected

  29. 29

    How to update selected row in datagridview through textbox located on another form?

HotTag

Archive