Multi row selection without pressing the control button

Multi row selection without pressing the control button

In this post will explain you how to get multi select row without pressing the control button. In order to achieve multi row section in DataGridView control follows below steps. As we can see in image.
Multi row selection image 1.1
First step to create a window form application after that add user control and put a DataGridView control on user control, after that change the user control inheritance class below is the code. By default user control inherit UserControl class we need to change it.

public partial class DataGridViewUC : DataGridView

After that we need to override following event of user control below is the event.
1-OnCellMouseDown
2-OnCellMouseClick
3-OnDataSourceChanged

Below is the overridden event code.

protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
{
this.Rows[e.RowIndex].Selected = !this.Rows[e.RowIndex].Selected;
//base.OnMouseDown(e);
}

protected override void OnCellMouseClick(DataGridViewCellMouseEventArgs e)
{
//base.OnMouseClick(e);
}

protected override void OnDataSourceChanged(EventArgs e)
{
base.OnDataSourceChanged(e);
}

We have to comment the base event call as I have commented above.

Summary:
In this article I tried to explain and implement the multi row selection in datagridview window forms. I would like to have feedback and question from my blog reads, please post your comment and question in order to make it more useful. You can download code from here Multi row selection without pressing control button.

One thought on “Multi row selection without pressing the control button

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s