How to disable RowHeader on a DataGridView

折月煮酒 提交于 2019-12-25 03:29:09

问题


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();
 }

来源:https://stackoverflow.com/questions/53233848/how-to-disable-rowheader-on-a-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!