[英]Disabling column header in datagridview C#
I have a datagridview 'audit_TrailDataGridView'. 我有一个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). 可能发生了一些不良情况,因为当用户单击标题时,会引发一个事件,该事件旨在处理用户单击实际单元格而不是标题时的情况(例如,
CellDoubleClick
事件)。 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. 我在
dataGridView1_SelectionChanged
事件中遇到了类似的问题。
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. 我希望在单击标题列时对DataGridView进行排序,但不实现我想为非标题行单击而运行的代码。
So basically I found a stupid solution, I added a huge try catch
block inside dataGridView1_SelectionChanged
method containig everything in this method. 所以基本上我找到了一个愚蠢的解决方案,我在
dataGridView1_SelectionChanged
方法中添加了一个巨大的try catch
块,该方法包含该方法的所有内容。
Maybe this will work for you or someone else too. 也许这对您或其他人也有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.