C#VS2015 - for循环为datagridview中的一堆列设置标题文本对齐属性 [英] C# VS2015 - for loop to set header text alignment property for a bunch of columns in a datagridview

查看:215
本文介绍了C#VS2015 - for循环为datagridview中的一堆列设置标题文本对齐属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,来自巴西的问候!我是初学程序员在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;



等......

解决方案

DataGridView的文档可用在; MSDN - DataGridView类

[ ^ ]

通过阅读本文,您可以了解控件,可用的构造函数,方法,属性和事件。文档通常包含示例和操作方法信息

这是您通过阅读和学习学习成为开发人员的方式。

请不要认为我是粗鲁或讨厌的,但是如果你给男人一条鱼就说 ... 是大多数开发者会看到这个问题的方式。

制作一个循环并不难 - 链接到文档; 关键字(C#参考) [ ^ ] - 您需要一个初始值设定项条件迭代器

因此你应该使用类似的东西;

  for  int  initializer =  0 ;初始值设定项<  myGrid。< Property> ;; initializer ++)
{
/ / 做好工作
}





种类此致


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 ...

解决方案

The documentation for the DataGridView is available at; MSDN - DataGridView Class
[^]
By reading this you can learn about the control, the available constructors, methods, properties and events. The documentation will typically contain examples and "how-to" information
This is how you learn to become a developer - by reading and learning.
Please don't think I am being rude or nasty but the saying if you give a man a fish... is how most developers will see this question.
Making a loop is not hard - link to documentation; for Keyword (C# Reference)[^] - you need an initializer, a condition and an iterator
You should therefore using something like;

for(int initializer = 0; initializer < myGrid.<Property>; initializer++)
{
    // do work
}



Kind Regards


这篇关于C#VS2015 - for循环为datagridview中的一堆列设置标题文本对齐属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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