简体   繁体   English

C#DataGridView禁用列标题中的排序图标

[英]C# DataGridView Disable sort icon from the column header

I have a Winforms DataGridView with few columns which can be sorted and few which couldn't be. 我有一个Winforms DataGridView,几列可以分类,少数不可能。 For columns which I don't want my gridview to be sorted I have set 对于我不希望我的gridview进行排序的列我已设置

dgvConnections.Columns[e.ColumnIndex].SortMode = DataGridViewColumnSortMode.NotSortable; in

dgvConnections_ColumnHeaderMouseClick event handler but I am unable to get rid of the the sort icon from the column header, as its presence could cause confusion to the user. dgvConnections_ColumnHeaderMouseClick事件处理程序,但我无法从列标题中删除排序图标,因为它的存在可能会导致用户混淆。

So kindly suggest me a way to get rid of the sorting icon from the column which cannot be sorted. 所以请建议我摆脱列中无法排序的排序图标。 Thanks in advance! 提前致谢!

It looks like you are not maintaining the correct execution order. 看起来您没有维护正确的执行顺序。 The code you wrote will do the work 你写的代码将完成工作

dgvConnections.Columns[e.ColumnIndex].SortMode = DataGridViewColumnSortMode.NotSortable;

but make sure you are calling it after initializing the DataGridView. 但请确保在初始化DataGridView后调用它。

If you want it for specific columns like you mentioned in your question, you need to find the index and set the sortmode. 如果您想要在问题中提到的特定列,则需要找到索引并设置sortmode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM