在 DataGridView 中禁用列标题排序的最佳方法 [英] Best way to disable the column header sorting in DataGridView

查看:42
本文介绍了在 DataGridView 中禁用列标题排序的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 DataGridView 中禁用列标题排序.

I need to disable the column header sorting in DataGridView.

我们可以通过设置单个列的属性来做到这一点

We can do that by setting the property of individual columns like

BalancesGridView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;

如果是这种情况,那么我将不得不遍历所有列.

If this is the case , then I'll have to loop through all the columns.

有没有更好的方法?

推荐答案

不,我认为直接在列上设置 SortMode 是最好的.但老实说,谁在乎呢?一个简单的循环有什么不好?

No, I think setting the SortMode on the column directly is as good as it gets. But honestly, who cares? What's so bad about a simple loop?

这篇关于在 DataGridView 中禁用列标题排序的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆