CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2018-06-08
by kaj

Original Post

Original - Posted on 2010-06-14
by Data-Base



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Replace your code in mouseDown event with this :
private void MyDataGridView_MouseDown(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Right) { var hti = MyDataGridView.HitTest(e.X, e.Y); MyDataGridView.ClearSelection(); MyDataGridView.Rows[hti.RowIndex].Selected = true; } }
I believe it should work.
I finally solved it:
* In Visual Studio, create a ContextMenuStrip with an item called "DeleteRow"
* Then at the DataGridView link the ContextMenuStrip
Using the code below helped me getting it work.
this.MyDataGridView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyDataGridView_MouseDown); this.DeleteRow.Click += new System.EventHandler(this.DeleteRow_Click);
Here is the cool part
private void MyDataGridView_MouseDown(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Right) { var hti = MyDataGridView.HitTest(e.X, e.Y); MyDataGridView.ClearSelection(); MyDataGridView.Rows[hti.RowIndex].Selected = true; } }
private void 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 :-)
I welcome any correction if there is an error.

        
Present in both answers; Present only in the new answer; Present only in the old answer;