Hi,
Does anyone have a good way to select all / none of the rows in a DataGridView?
Regards,
Bård
Hi
How about using a select All / Select None checkbox to do the selection?
Regards
Ewan
Hi Ewan,
Thank you for your reply.
I found a way to do it now, with this code in button click event handlers.
private void btnSelectAll_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dgvInvoices.Rows) { row.Selected = true; } }
Hello Bård, Please be aware that your code sets all rows of the DataGridView to be selected. Even rows that are not on the currently displayed DataGridView page. A service SelectDataGridViewRowsBetween method could help you here. It could take a DataGridView object and two integers for row indices. You could use code like so: protected virtual void SelectDataGridViewRowsBetween(DataGridView objDataGridView, int intStartRow, int intEndRow) { if (objDataGridView != null && objDataGridView.Rows.Count > 0 && intStartRow >= 0 && intEndRow >= 0 && intStartRow <= intEndRow && intEndRow < objDataGridView.Rows.Count) { for (int intRowIndex = intStartRow; intRowIndex < intEndRow; intRowIndex++) { objDataGridView.Rows[intRowIndex].Selected = true; } } } You can also create a service method for selecting DataGridView rows in a specific page that would be able to call the previous method. Regards, Ori Cohen Support Manager, the Visual WebGui team