1
votes

I'm making an application with windows forms and a DataGridView but have a little problem here.

I've tried a couple of things but it seems that I can't remove this focus around the Selected Cell (Dotted line).

enter image description here

And I'd like to make it look like this when the row is clicked:

enter image description here

Just simply remove the dotted line all together from DGV. Is it possible?

Row selection is set to FullRowSelect, TabStop is False, MultiSelect is False. I've also tried with e.PaintParts in CellPainting to no avail. Any hints?

1
Do you allow to move from Cell to Cell using the TAB key (i.e., StandardTab = false)? If not, you could use SendMessage to send WM_CHANGEUISTATE with mask (UISF_HIDEACCEL | UISF_HIDEFOCUS << 16) | UIS_SET in the Enter event of the DGV. This disables focus cues. Otherwise, you need a Custom Control, derived from DataGridView, to override ShowFocusCues (e.g., protected override bool ShowFocusCues => false;) - Jimi
StandardTab is already set to false. I'm a bit confused by the SendMessage part so I chose to try the DGV Custom Control to set ShowFocusCues to false. Now, when I start the application it works just fine until Tab is pressed anywhere on the form, then it shows Cues again and sometimes when I start the application it works just fine, sometimes it just doesn't (even without Tab pressed). I'm a bit confused of what is going on o.O - q1werty
StandardTab should be set to true (to TAB outside the Control instead of moving the Focus to the next Cell). Try to set this in the Enter event of your DGV: SendMessage([DataGridView].Handle, WM_CHANGEUISTATE, (IntPtr)((3 << 16) | 1), IntPtr.Zero);, where WM_CHANGEUISTATE = 0x0127 (with StandardTab = true). - Jimi
I just tried, every line in that code is underlined with red, doesn't exist in the current context. I've never used SendMessage before, I might be doing something wrong here because I just pasted your code to Enter event. Do I have to create SendMessage variable first? - q1werty
SendMessage is a Win32 function, you have to PInvoke it: using System.Runtime.InteropServices; [...] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern int SendMessage(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam); - Jimi

1 Answers

2
votes

The only thing that worked for me was to create a custom control that inherits from DataGridView and then override the ShowFocusCues like this:

protected override bool ShowFocusCues
    {
        get
        {
            return false;
        }
    }