How can I retrieve all the values from a row in a DGV into an array?

Daniel McElhinney 120 Reputation points
2023-03-03T03:39:52.1433333+00:00

How can I retrieve all the values from a row in a DGV into an array?

Thank you

Developer technologies | Windows Forms
Developer technologies | .NET | Other
Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.9K Reputation points
    2023-03-03T05:22:20.1766667+00:00

    If you are using the data binding, then get the values from the source object.

    Or try this:

    Dim values As Object() = DataGridView1.Rows(0).Cells.Cast(Of DataGridViewCell).Select(Function(c) c.Value).ToArray
    

    This example gets the first row. Use another index or adjust it for your needs.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.