Selecting all Rows in a DataGridView

3

I would like to know how I can select all Rows of a DataGridView .

Code that I have:

DataGridView.Rows[0].Cells[0].Value.ToString();
    
asked by anonymous 16.10.2016 / 17:18

1 answer

4

Use the DataGridView.SelectAll method to select all the lines:

dataGridView1.SelectAll();

To select the rows of a specific column, do so, for example in click of a button:

void Button1Click(object sender, EventArgs e)
{
    dataGridView1.ClearSelection();

    for(int i = 0; i < dataGridView1.RowCount; i++)
        dataGridView1[0, i].Selected = true; // "0" Indica a primeira coluna
}
    
16.10.2016 / 17:21