How to disable RowHeader on a DataGridView

315 Views Asked by At

How can I prevent from clicking or selecting RowHeaders?
I want that when a new user clicks on a row or cell, then move all information to an update Form and it's working fine.

But, if a user clicks on a RowHeader, then it should select all rows and generate an error.

I know I can hide RowHeaders, but I want to show RowHeaders and I want to prevent users from clicking on them.

I have used the SelectionMode property of the DataGridview and set it to CellSelect/FullRowSelect etc, but it did not help.

Is it possible to disable RowHeaders and not let people select RowHeaders?

Here is my code so far:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{ 
    decimal accNo = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
    var item = db.UserAccount.Where(a => a.AccountNo == accNo).FirstOrDefault(); 

    txtAccountNo.Text = item.AccountNo.ToString();

    txtFirstName.Text = item.FirstName;
    txtLastName.Text = item.LastName;
    txtAddressUpNew.Text = item.Address.ToString();
 }
0

There are 0 best solutions below