Try to edit the DefaultCellStyle property of the grids (in Form Designer). Change the SelectionBackColor. Use a green colour that is used for your columns.
DataGridView: Unable to 'De-select' Cell
I am having trouble removing the blue background from a DataGridView Cell (2 actually).
The DataGridViews have NO selected cells and NO CurrentCells (CurrentCellAddress = -1, -1),
Neither DataGridView is the ActiveControl, yet the Blue Background persists: one Cell in each.
See screenshot below in which the 'End' button is the active control.What does the blue background mean? How do I get rid of it? Both DGViews are ReadOnly.
2 answers
Sort by: Most helpful
-
-
Jiale Xue - MSFT 45,006 Reputation points Microsoft Vendor
2024-03-20T08:19:53.13+00:00 Hi @Tony Hedge , Welcome to Microsoft Q&A,
You can clear selected cells using ClearSelection(). At the same time, modify the enable attribute so that it cannot be selected.
using System.Windows.Forms; namespace xxx { public partial class Form1 : Form { public Form1() { InitializeComponent(); // Set up the first DataGridView dataGridView1.ReadOnly = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AllowUserToAddRows = false; // Disable users from manually adding rows // Set up the second DataGridView dataGridView2.ReadOnly = true; dataGridView2.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView2.AllowUserToAddRows = false; // Disable users from manually adding rows //Add sample data for two DataGridViews // This assumes you already have a data source, otherwise you need to set the data source for the two DataGridViews // Just added some sample data here for demonstration purposes dataGridView1.Columns.Add("Column1", "Column1"); dataGridView1.Columns.Add("Column2", "Column2"); dataGridView1.Rows.Add(new object[] { "Data1", "Data2" }); dataGridView1.Rows.Add(new object[] { "Data3", "Data4" }); dataGridView2.Columns.Add("Column1", "Column1"); dataGridView2.Columns.Add("Column2", "Column2"); dataGridView2.Rows.Add(new object[] { "Data5", "Data6" }); dataGridView2.Rows.Add(new object[] { "Data7", "Data8" }); dataGridView1.Enabled = false; // Disable the first DataGridView dataGridView2.Enabled = false; } private void Form1_Load(object sender, System.EventArgs e) { dataGridView1.ClearSelection(); dataGridView2.ClearSelection(); } } }
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.