如何设置 DataGridViewCell 中字符串的方向?
如何为 DataGridViewColumn 中的特定 DataGridViewCell 设置 RightToLeft
属性?
How do I set the RightToLeft
property for a particular DataGridViewCell in a DataGridViewColumn?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是一个老问题,但正如其他人所说, DataGridViewCell 和 DataGridViewColumn 没有 RightToLeft 属性。但是,有解决此问题的方法:
处理
CellPainting
事件并使用TextFormatFlags.RightToLeft
标志:(代码取自CodeProject问题.)
如果 DGV 中只有一个特定单元格,您可以尝试插入不可见的 CodeProject 问题。 wikipedia.org/wiki/Right-to-left_mark" rel="noreferrer">RTL 字符 (U+200F) 位于单元格内容的开头。
I know it's an old question, but as others said,
DataGridViewCell
andDataGridViewColumn
don't have theRightToLeft
property. However, there are workarounds to this problem:Handle the
CellPainting
event and use theTextFormatFlags.RightToLeft
flag:(Code taken from CodeProject question.)
If it's only one particular cell in the DGV, you may try to insert the invisible RTL character (U+200F) in the beginning of the cell content.
这样的属性不存在。您需要设置
RightToLeft整个控件的 code> 属性
。
我怀疑您试图滥用该属性来右对齐您的文本。它旨在支持使用从右到左字体的区域设置,而不是自定义格式。
如果您的目标是更改格式,则每个
DataGridViewCell
都有一个Style
属性,接受DataGridViewCellStyle
类。您可以设置其对齐
属性 设置为“MiddleRight”,将单元格内容垂直居中对齐,水平居右对齐。有关详细信息,请参阅:如何:设置 Windows 窗体 DataGridView 控件中的数据格式。Such a property does not exist. You need to set the
RightToLeft
property of the entire control.I suspect that you're attempting to mis-use the property to right-justify your text. It's intended to enable support for locales that use right-to-left fonts, not for custom formatting.
If altering formatting is your goal, each
DataGridViewCell
has aStyle
property that accepts an instance of theDataGridViewCellStyle
class. You can set itsAlignment
property to "MiddleRight" to align the content of the cell vertically at the middle and horizontally at the right. For more information, see: How to: Format Data in the Windows Forms DataGridView Control.要对整个列执行此操作,请使用
虽然我相信单个单元格的样式将覆盖它。
To do so for the whole column, use
Although I believe the individual cell's style will override this.
就这么简单:
As simple as that:
我知道这是一篇相当旧的帖子,但很多时候我找到旧帖子的答案同样有助于为我指出解决方案,所以无论如何我都会发布我的解决方案。
我通过处理 datagridview 的 EditingControlShowing 事件来做到这一点。在解决这个问题时,让我困惑的一件事是我试图在 datagridviewcell 中寻找 RightToLeft 属性,但这是 Textbox 的属性。
I know this is quite an old post, but many times I have found answers to an old post just as helpful to point me to a solution, so I will post my solution anyway.
I did this by handling the EditingControlShowing event of the datagridview. One thing that was throwing me off when solving this was that I was trying to look for a property RightToLeft in a datagridviewcell, however that is a property of Textbox instead.