Introduction
Sometimes, we need to create an application in which Datagridview doesn’t allow to give functionality to user to put focus on a particular cell. It's a very needed requirement which we face from time to time. Suppose a user has a value and he doesn’t want to make it editable, and wants to prevent it from any focus. In this case, this article might help you.
You Need to Know
Like every control, DataGridView has some by default value like DataGridView navigation model does not have any ability to restrict focus to a specific cell.
To implement functionality to give access to user to prevent cell from focus of users, we need to implement our own navigation logic by overriding the appropriate keyboard, navigation and mouse methods such as DataGridView.OnKeyDown, DataGridView.ProcessDataGridViewKey,DataGridView.SetCurrentCellAddressCore, DataGridView.OnMouseDown.
Let's see an example if you want to prevent user to give focus on second column of DataGridView. Then in this case, you need to drive DataGridView class and override the SetCurrentCellAddressCore and SetSelectedCellCore to accomplish the logic you want to perform.
How It Will Look
You can see that the user is able to focus on almost every column except 1st (NationalIDNumber) Column of DataGridView control.
Animated Image - Preventing Cell of DataGridView
How to Do
Take a look at the given images and code to learn how to perform it.
It's better to create a different class and for it, you need to perform the following steps as shown in the given figure.
Right click on Project name under solution Explorer and then Select Add and then click on Class as shown below:

It will AddNewItem Form where you can select class and then need to name it (class).

Now Select Class from Visual C# Items and enter the Name (Example MyDataGridView.cs) in textbox and then press Add button.
When you press Add button, it will create a new class in your Program under Solution Explorer so after creating class we need to inherit DataGridView class with current class (MyDataGridView).
Take a look how:

and DataGridView class is accessible only when you’ve declared
Windows.Form namespace like.
Note: To access DataGridView class you, need to include System.Window.Form namespace in your program.
Using System.Windows.Forms
and then the entire code of DataGridview class will be:
public class myDataGridView : DataGridView
{
private int columnToSkip = -1;
public int ColumnToSkip
{
get { return columnToSkip; }
set { columnToSkip = value; }
}
protected override bool SetCurrentCellAddressCore(int columnIndex, int rowIndex,
bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick)
{
if (columnIndex == this.columnToSkip && this.columnToSkip != -1)
{
if (this.columnToSkip == this.ColumnCount - 1)
{
return base.SetCurrentCellAddressCore(0, rowIndex + 1,
setAnchorCellAddress, validateCurrentCell, throughMouseClick);
}
else
{
if (this.ColumnCount != 0)
{
return base.SetCurrentCellAddressCore(columnIndex + 1, rowIndex,
setAnchorCellAddress, validateCurrentCell, throughMouseClick);
}
}
}
return base.SetCurrentCellAddressCore(columnIndex, rowIndex,
setAnchorCellAddress, validateCurrentCell, throughMouseClick);
}
protected override void SetSelectedCellCore
(int columnIndex, int rowIndex, bool selected)
{
if (columnIndex == this.columnToSkip)
{
if (this.columnToSkip == this.ColumnCount - 1)
{
base.SetSelectedCellCore(0, rowIndex + 1, selected);
}
else
{
if (this.ColumnCount != 0)
{
base.SetSelectedCellCore(columnIndex + 1, rowIndex, selected);
}
}
}
else
{
base.SetSelectedCellCore(columnIndex, rowIndex, selected);
}
}
}
When collapsing each and every function of class, the program will look as given below.
Now compile the application once to bring existence of myDataGridView control in toolbox. After one successful execution, it will be shown in Toolbox as given below and then we can drag it from toolbox to Form and use it with some additional functionality.

Now, you need to write query to ” bind DataGridView with your database ” as given below. Here, I am using AdventureWorks database to bind DataGridView, you can see at last two circled lines in which the first line is responsible to bind DataGridview to datasource and the very last line is responsible for skipping value of 1st column of DataGridView. Take a look:

Now Press F5 or compile it to see the effect.
You will notice that every column is accessible except the first column which is bounded with a red circle.