Forum  Commercial Foru...  Commercial Foru...  DataGridView - Select All / None
Previous Previous
 
Next Next
New Post 1/4/2010 4:52 AM
Resolved
  myrstad@gmail.com
6 posts
No Ranking


DataGridView - Select All / None 

Hi,

Does anyone have a good way to select all / none of the rows in a DataGridView?

Regards,

Bård

 
New Post 1/4/2010 4:59 AM
  Ewans
464 posts
2nd Level Poster




Re: DataGridView - Select All / None 

Hi

How about using a select All / Select None checkbox to do the selection?

Regards

Ewan

 
New Post 1/4/2010 5:54 AM
Accepted Answer 
  myrstad@gmail.com
6 posts
No Ranking


Re: DataGridView - Select All / None 
Modified By myrstad@gmail.com  on 1/4/2010 8:58:59 AM)

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;
            }
        }

 
New Post 1/4/2010 7:02 AM
  ori.cohen
4383 posts
1st Level Poster




Re: DataGridView - Select All / None 
Modified By ori.cohen  on 1/4/2010 10:03:07 AM)

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

 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  DataGridView - Select All / None
Assessment Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS