How do you draw a border around a DataGridView cell while it's being edited?

后端 未结 3 1187
野性不改
野性不改 2020-12-16 18:05

I would like to draw a red border around a DataGridView cell while it\'s being edited.

I\'ve managed to draw a red border around the selected cell while

3条回答
  •  無奈伤痛
    2020-12-16 18:31

    It seems like the EditingControl is hosted in a parent Panel, and if you set the Opaque style of that panel to true, then the border will be painted.

    E.g.

    void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) {
        var c = e.Control;
        var p = c.Parent;
        SetStyles(p, ControlStyles.Opaque, true);
    }
    
    private static void SetStyles(Control c, ControlStyles styles, bool value) {
        MethodInfo mi = typeof(Control).GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance);
        mi.Invoke(c, new Object[] { styles, value });
    }
    

提交回复
热议问题