问题描述
大家好,来自巴西的问候!我是初学程序员在Visual Studio 2015中开发C#WinForms解决方案。我有一个包含35列的DataGridView,我想知道如何以编程方式执行FOR循环,将标题文本对齐设置为仅从第4列到第20列居中。我知道如何逐列完成,但我确信必须有更快/更聪明的方法来做到这一点。请参阅下面我正在使用的代码。非常感谢您的时间和帮助!
我尝试过:
alunos_detDataGridView.Columns [4] .HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter;
alunos_detDataGridView.Columns [5] .HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter;
等......
Hello guys, greetings from Brazil! I'm a beginner programmer developing a C# WinForms solution in Visual Studio 2015. I have a DataGridView with 35 columns and I was wondering how to programatically do a FOR loop to set the header text alignment to center only from column 4 through 20. I know how to do it column by column but I'm sure there must be a faster / smarter way to do it. See below the code I'm using. Thank you very much for your time and help!
What I have tried:
alunos_detDataGridView.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter;
alunos_detDataGridView.Columns[5].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomCenter;
and so forth ...
这篇关于C#VS2015 - for循环为datagridview中的一堆列设置标题文本对齐属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!