Reputation: 4929
I have a DataGridView control that allows for multi row selecting. The issue I have is with the current position of the selection being shown (see image below). I would like to NOT have the current cell position shown at all. Is that possible?
I would like it to look like the following instead...
Upvotes: 2
Views: 638
Reputation: 5454
Derive a class from DataGridView
and override the ShowFocusCues
property.
True
to show the focus rectangle.False
to hide the focus rectangle.base.ShowFocusCues
to maintain default behavior.You can also expose a public property to change it dynamically.
public class DataGridViewFocused : DataGridView
{
public bool? ShowFocus { get; set; }
protected override bool ShowFocusCues
{
get
{
return this.ShowFocus.HasValue? this.ShowFocus.Value : base.ShowFocusCues;
}
}
}
Adding it to your project to replace any existing DataGridView
can be as simple as navigating into your Form.Designer.cs
file and replacing the following:
public System.Windows.Forms.DataGridView dataGridView1;
this.dataGridView1 = new System.Windows.Forms.DataGridView();
with:
public DataGridViewFocused dataGridView1;
this.dataGridView1 = new DataGridViewFocused();
From there you can always hide the focus rectangle by adding the following line:
this.dataGridView1.ShowFocus = false;
Or, for example, if you wanted to hide that rectangle only during a multiple-select event, you could do something like the following:
private void DataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedCells.Count > 1)
{
this.dataGridView1.ShowFocus = false;
}
else
{
this.dataGridView1.ShowFocus = null;
}
}
Upvotes: 1