Select All Cells from Datagridview

Joined
Nov 7, 2008
Messages
20
Programming Experience
Beginner
I want to select all cells from datagrid for doing futhur operation. I had use following code but it read only one selected data from datagrid .

VB.NET:
DataGridView1.SelectedCells.Item(0).Value

please help me to read all data from datagrid cells . Thanks
 
Its not very clear what you wanted, if you want to do something to all the cells in a datagridview heres one way..

VB.NET:
        For Each r As DataGridViewRow In DataGridView1.Rows
            For Each c As DataGridViewCell In r.Cells
                If c.Value IsNot Nothing Then
                    '// Do whatever.
                    MessageBox.Show(c.Value.ToString)
                End If
            Next
        Next

If you just want to select them all use DataGridView1.SelectAll()

Hope this want you wanted to know! :)
 
Back
Top