Since the default action .net will also update slectedrowsyours datagridview, you need to have an array to reserve the old options:
DataGridViewRow[] old;
which will be updated in CellMouseDown(before the default .net action changes your choice):
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
old = new DataGridViewRow[dataGridView1.SelectedRows.Count];
dataGridView1.SelectedRows.CopyTo(old,0);
}
RowHeaderMouseClick ( RowHeaderSelect - datagridview selectionmode ) CellMouseClick FullRowSelect :
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
foreach (DataGridViewRow gr in old)
{
if (gr == dataGridView1.CurrentRow)
{
gr.Selected = false;
}
else
{
gr.Selected = true;
}
}
}
: :
datagridview, , OnCellMouseDown & OnCellMouseClick, . :
Using System;
Using System.Windows.Forms;
public class myDataGridView:DataGridView
{
protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
{
this.Rows[e.RowIndex].Selected = !this.Rows[e.RowIndex].Selected;
}
protected override void OnCellMouseClick(DataGridViewCellMouseEventArgs e)
{
}
}
Form.Designer.cs datagridview datagridview1 ( ) myDataGridView......
:
private System.Windows.Forms.DataGridView dataGridView1; to
private myDataGridView dataGridView1;
this.dataGridView1=new System.Windows.Forms.DataGridView() to
this.dataGridView1=new myDataGridView ()