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

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,647 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.7K 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