The DataGridView is a powerful grid control included in the .NET Framework.  One function missing, however, is the ability to hide the current selection when the DataGridView control is not focused.  What the DataGridView class needs is a HideSelection property, similar to the ListView and TextBox.  But the .NET designers have not included this capability in the DataGridView class.

Following is a control derived from DataGridView that will automatically hide the current selection when a DataGridView loses focus, and show the selection when the DataGridView regains focus:

ASP.NET Web Hosting – 3 Months Free and Free Setup

public class DataGridViewEx : DataGridView
{
    private DataGridViewCell m_Cell;
    protected override void OnGotFocus( EventArgs e )
    {
        if (this.m_Cell != null)
            this.CurrentCell = this.m_Cell;
        base.OnGotFocus( e );
    }
    protected override void OnLostFocus( EventArgs e )
    {
        this.m_Cell = this.CurrentCell;
        this.CurrentCell = null;
        base.OnLostFocus( e );
    }
}

Related posts:

  1. Enter Key in DataGridView
  2. C# Focus TextBox on Form Load
  3. Hide Form from Alt+Tab
  4. Hide Visual Studio Macro Balloon
  5. C# Overloaded Methods with Inherited Arguments