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

  • Home
  • SEARCH
  • 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 6219871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:51:33+00:00 2026-05-24T07:51:33+00:00

I have a function to delete single rows on right click delete in a

  • 0

I have a function to delete single rows on right click delete in a datagridview..

code:

  private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
    {

            if (e.Button == MouseButtons.Right)
            {
                var hti = dataGridView1.HitTest(e.X, e.Y);
                if (hti.RowIndex != -1)
                {
                    dataGridView1.ClearSelection();
                    dataGridView1.Rows[hti.RowIndex].Selected = true;
                }
            }          
    }

    private void DeleteRow_Click(object sender, EventArgs e)
    {
            Int32 rowToDelete = dataGridView1.Rows.GetFirstRow(DataGridViewElementStates.Selected);
            if (rowToDelete != -1)
            {
                dataGridView1.Rows.RemoveAt(rowToDelete);
                dataGridView1.ClearSelection();
            }          
    }

but now I want to delete multiple rows on selection.
First I don’t know why I cannot select multiple rows.
Second I want to delete multiple delete using the delete button and right click mouse delete.

Can someone help me?

  • 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-05-24T07:51:34+00:00Added an answer on May 24, 2026 at 7:51 am

    Edit:
    Take a look at your code. You are setting the selected row depending on the results of the HitTest method. The DataGridView property SelectedRows will determine which rows are selected. Not sure why you need to execute a HitTest, but then again perhaps you haven’t fully explained the desired functionality.

    if (e.Button == MouseButtons.Right)
    {
        var hti = dataGridView1.HitTest(e.X, e.Y);
        if (hti.RowIndex != -1)
        {
            dataGridView1.ClearSelection();
            dataGridView1.Rows[hti.RowIndex].Selected = true;
        }
    }
    

    Make sure that the MultiSelect property is set to true on your datagrid.

    Then, you can utilize the SelectedRows property in the event of your choice:

    foreach (DataGridViewRow row in DataGridView1.SelectedRows)
    {
        DataGridView1.Rows.Remove(row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listener like this: $('.delete').click(function() { ...some stuff }); Also, on the
I have this code $(.delete2).click(function() { $('#load2').fadeIn(); } I have dynamically added item via
In my Java code I have function that gets file from the client in
I have a PHP application, which has a delete function on one of the
I have the following problem with this code: <button id=delete>Remove items</button> $(#delete).button({ icons: {
Hi have the following function which works fine: jQuery('.btnRemoveItem').click(function(obj){ jQuery(this).closest('li').fadeOut(400, function() { $(this).remove(); });
I have been writing same code for insert, update, delete with LINQ over and
I have a form that searches all rows in a single table (TServices) that
i have the code as below : class Singleton { private: int i; static
I have this line of code: delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic',

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.