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 690967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:29:28+00:00 2026-05-14T02:29:28+00:00

I have a datagridview that I have put a ContextMenuStrip1 on. I would like

  • 0

I have a datagridview that I have put a ContextMenuStrip1 on. I would like it to remove a row in the datagridview when the row is right clicked on and they click on “delete row”. I have the delete working and the menu is showing up but this isn’t firing when you right click on the datagridview.

This is where I am setting the row to edit:

   Private Sub ModifyRowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModifyRowToolStripMenuItem.Click
    If Not datagridview_TagAssignment.CurrentRow Is Nothing Then
      datagridview_TagAssignment.CurrentCell = datagridview_TagAssignment.Item(0, datagridview_TagAssignment.CurrentRow.Index)
      datagridview_TagAssignment.BeginEdit(True)
    End If
  End Sub

I am always ending up on row(0) and never the row I right clicked on.

 Private Sub datagridview_TagAssignment_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles datagridview_TagAssignment.CellMouseClick
    If e.Button = Windows.Forms.MouseButtons.Right AndAlso e.RowIndex >= 0 Then
      datagridview_TagAssignment.Rows(e.RowIndex).Selected = True
    End If
  End Sub

Anyone have any suggestions?

  • 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-14T02:29:28+00:00Added an answer on May 14, 2026 at 2:29 am
    Private Sub DataGridView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            rowClicked = DataGridView1.HitTest(e.Location.X, e.Location.Y).RowIndex
            ContextMenuStrip1.Items.Add(rowClicked.ToString)
            ContextMenuStrip1.Show(DataGridView1, e.Location)
            ContextMenuStrip1.Items.Clear()
        End If
    End Sub
    

    Edit: Updated to handle a context menu strip.

    That should give you the row index of the row that was right clicked using the mouse coordinates. Which should let you delete the row based on knowing the index.

    Edit

    Per Your comment on it not working this is my code

    I have a Solution with a WinForm with a dataGridView added to it. and this is the code in the form.

    Public Class Form1
    
        Dim bindS As New BindingSource
        Dim rowClicked As Integer
        Private Sub DataGridView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
            If e.Button = Windows.Forms.MouseButtons.Right Then
                rowClicked = DataGridView1.HitTest(e.Location.X, e.Location.Y).RowIndex
                ContextMenuStrip1.Items.Add(rowClicked.ToString)
                ContextMenuStrip1.Show(DataGridView1, e.Location)
                ContextMenuStrip1.Items.Clear()
            End If
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim s As New List(Of String)
            s.Add("String one")
            s.Add("String Two")
            bindS.DataSource = s
            DataGridView1.DataSource = bindS
    
    
        End Sub
    End Class
    

    Right Clicking on a row shows the correct row index

    Make sure that the event args that you are handling are the System.Windows.Forms.MouseEventArgs I noticed that you’re handling the cell click

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

Sidebar

Related Questions

I have a DataGridView that I would like all values on a specific row
I have a DataGridView that gets a datasource assigned. I would like to create
I have a winforms datagridview that seems to always have at least one row
I have Datagridview .. selected a row .i want that row to be added
I have created a UserControl in C# that I have put a DataGridView on.
I would like to fill in my DataGridView with a DataView that we can
I have a DataGridView that I want to query using Linq (C# WinForm). I
I have a DataGridView that is bound to a list of objects called BaseChange.
I have a datagridview that may or may not have rows selected when the
I have a DataGridView that's bound to a DataSet. It has columns DateCreated, Weight,

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.