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.