Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:25:38+00:00 2026-06-17T06:25:38+00:00

I have a windows form in which we have a DataGridView . The property

  • 0

I have a windows form in which we have a DataGridView. The property of that is cell select and I have a ContextMenustrip in which there is a menu named select all when select all is clicked it should change the property of DataGridView of the selected cell to the FullRowSelect and the selection should be on the same row which I have clicked. the problem is when i click on a cell the default property is cell select and when I click on select all of the ContextMenustrip the selected cell is not selected and I have to re-select that row I want that when the form opens and when i click on particular cell and when i click on select all of the ContextMenustrip is clicked then the same row should be selected on which I have clicked the cell previously this is my code.

private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:25:39+00:00Added an answer on June 17, 2026 at 6:25 am

    If I’m reading your question correctly, you want to select the entire row when the “Select All” option of a context menu is clicked. If that is correct, you might try:

    dataGridView1.SelectedCells[0].OwningRow.Selected = true;
    

    or

    foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
        cell.OwningRow.Selected = true;
    

    You will need to remove the following line first:

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    

    The above line will put the DataGridView into full-row select mode, in which the SelectedCells property will not be used, and you will then see the following exception when you click the Select All option in your context menu.

    Index was out of range. Must be non-negative and less than the size of the collection.
    

    The entire function should look like this:

    private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
    {
        foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
            cell.OwningRow.Selected = true;
    }
    

    Note that the user will need to (left) click the cell whose row they want to select before right-clicking to bring up the context menu. Otherwise, the selection will not change, and the previously-selected cell’s row will be selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form MainForm which is a Windows Forms form that contains many
i have windows form which have a button, when button is clicked it dynamically
I have a windows form (Form1) which when a button is clicked on it
I have a Windows form which does not have a border, titlebar, menu, etc..
I have a windows form which calls other windows form that work within my
I have a DataGridView in my Windows Form, and it has a column which
I have a windows-form which runs without any problem and displayed well. But if
I have a requirement to create a windows form control which has to detect
I have a windows form app, and a class which is called Game. Let's
(Modifying the question)I have a windows form app in C# which calls into some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.