I have a datagridview 'audit_TrailDataGridView'. I need to disable the column headers of this ie: nothing should happen when user clicks on the column headers.
private void audit_TrailDataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
//do what?
}
Please help.
It could be that something undesirable happens because when a user clicks on a header an event is raised intended to handle the situation when a user clicks on an actual cell, not a header (for example, the CellDoubleClick
event). You need to manually check inside all such events that the cell clicked is not a header:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
//do something here
}
}
I had a similar problem with dataGridView1_SelectionChanged
event.
I wanted the DataGridView to be sorted when the header columns clicked, but not implement the code that I wanted to be runned for non-header row clicks.
So basically I found a stupid solution, I added a huge try catch
block inside dataGridView1_SelectionChanged
method containig everything in this method.
Maybe this will work for you or someone else too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.