如何:启用 Windows 窗体 DataGridView 控件中列的重新排序
如果你启用了 DataGridView 控件中的列重新排序,用户则可通过用鼠标拖动列标题来将列移动到新位置。 在 DataGridView 控件中,DataGridView.AllowUserToOrderColumns 属性值确定用户是否可以将列移动到不同的位置。
Visual Studio 中对此任务提供支持。 另请参阅如何:使用设计器在 Windows 窗体的 DataGridView 控件中启用列重新排序。
以编程方式启用列重新排序
将 DataGridView.AllowUserToOrderColumns 属性设置为
true
。dataGridView1.AllowUserToOrderColumns = true;
dataGridView1.AllowUserToOrderColumns = True
编译代码
此示例需要:
名为
dataGridView1
的 DataGridView 控件。对 System 和 System.Windows.Forms 程序集的引用。
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈