c# - Right click to select a row in a Datagridview and show a menu to delete it -


I have some columns in the DataGridView, and there are data in my rows. I see some solutions here, but I do not combine them can!

One way to right-click on one line, it will select the entire row and show a menu with the option to delete the row when this option will be deleted.

I made some efforts, but no one is working and it looks dirty. What should I do?

I finally solved it:

  • P> Using the code given below helped me to do this work.

      this.MyDataGridView.MouseDown + = New System.Windows.Forms.MouseEventHandler (This. MyDataGridView_MouseDown); This.DeleteRow.Click + = New System.EventHandler (this.DeleteRow_Click);  

    Here's a cool part

      Private Zero MyDataGridView_MouseDown (Object Sender, MouseEventArgs e) {if (e.button == MouseButtons.Right) {var Hti = MyDataGridViewTest (eX, eY); MyDataGridView.ClearSelection (); MyDataGridView.Rows [hti.RowIndex]. Selected = true; }} Private Zero DeleteRow_Click (Object Sender, EventArgs e) {Int32 rowToDelete = MyDataGridView.Rows.GetFirstRow (DataGridViewElementStates.Selected); MyDataGridView.Rows.RemoveAt (rowToDelete); MyDataGridView.ClearSelection (); }  

    I hope the code will help others: -)

    If there is an error, then I welcome any improvement.


Comments

Post a Comment

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -