Click here to Skip to main content
11,433,352 members (59,882 online)
Click here to Skip to main content

Tagged as

Preventing Deselect (Ctrl+Click) in GridRow

, 28 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Tip for preventing deselection of rows in DataGridView


This tip will help in preventing deselection of rows in the DataGridView control. Many would have come across this situation where-in always any random or specific row should be selected in the GridView.

Using the Code

The simple way to do that is to include the below line of code in the DataGridView CellMouseDown event. If you don't need right click option in the DataGridView control, then add this:

// if (e.Button == MouseButtons.Left)

Otherwise, remove it from the below code:

// GridViewCell Mouse Down Event
private void GridViewCellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
 // Check for Modifiers Key(CNTRL Key)
 if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
  if (e.Button == MouseButtons.Left)

Hope this tip will help you.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States
No Biography provided
Follow on   Twitter

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 28 Nov 2013
Article Copyright 2013 by AnthonyMG
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid