如何使用代码在DataGridTextColumn单元格文本上设置对齐方式 [英] How do I set alignment on DataGridTextColumn cell text using code

查看:198
本文介绍了如何使用代码在DataGridTextColumn单元格文本上设置对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试以编程方式添加DataGridTextColumn,并设置一些属性以在单元格中显示文本。

我不想使用TemplateColumn作为它需要双标签才能进入编辑模式。

我找不到可以设置文本对齐的代码。

任何人都知道怎么做到这一点?在此先感谢。

Hi,
I'm trying to add DataGridTextColumn programmatically, and set some properties to present the text in cells.
I don't want to use TemplateColumn as it requires double-tab to enter edit mode.
I can't find code that would set alignment of the text.
Anyone has any idea how to achieve this? Thanks in advance.

推荐答案

请看我对这个问题的评论。



你可以设置风格一个单独的单元格,用于整列:

DataGridViewColumn.DefaultCellStyle属性(System.Windows.Forms) [ ^ ],

DataGridViewBand.DefaultHeaderCellType属性(System.Windows.Forms) [ ^ ],

https://msdn.microsoft.com/en- us / library / system.windows.forms.datagridviewcell.style(v = vs.110).aspx [ ^ ]。



这就是全部。 :-)



-SA
Please see my comment to the question.

You can set the style of a separate cell individually, of for whole column:
DataGridViewColumn.DefaultCellStyle Property (System.Windows.Forms)[^],
DataGridViewBand.DefaultHeaderCellType Property (System.Windows.Forms)[^],
for individual cell: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.style(v=vs.110).aspx[^].

That's all. :-)

—SA


这篇关于如何使用代码在DataGridTextColumn单元格文本上设置对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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