Selecting All Rows from a Datagridview

Asked

Viewed 1,055 times

3

I wonder how I do to select all the Rows of a DataGridView.

Code that I have:

DataGridView.Rows[0].Cells[0].Value.ToString();

1 answer

4


Use the method DataGridView.SelectAll to select all lines:

dataGridView1.SelectAll();

To select the rows of a specific column, do so, for example in click one-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
}
  • Is there any way to adapt in mine? In case I want the Cells[0] of all lines.

  • But this code returns nothing, only clears the selection, traverses the dataGrid and selects the rows based on the column. In any case, if you want to open a new question and explain what you intend to do, it may be possible to reach a solution.

  • @But no longer answered here and here? (delete previous comments if possible!)

  • Yeah, it didn’t turn out the way I wanted it, but I’ll leave it at that. thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.