如何爲DataGridViewColumn中的特定DataGridViewCell設置RightToLeft
屬性?如何在DataGridViewCell中設置字符串的方向?
3
A
回答
2
這樣的屬性不存在。您需要設置整個控件的RightToLeft
property。
我懷疑你試圖誤用這個屬性來對你的文本進行正確的對齊。它旨在支持使用從右到左字體的區域設置,而不是自定義格式。
如果更改格式是您的目標,則每個DataGridViewCell
都有一個Style
property,它接受DataGridViewCellStyle
class的實例。您可以將Alignment
property設置爲「MiddleRight」,以便在中間垂直對齊單元的內容,並在右側水平對齊。有關更多信息,請參閱:How to: Format Data in the Windows Forms DataGridView Control。
1
爲了整個列爲此,使用
dataGridView.Columns["column name"].DefaultCellStyle.Alignment = DataGridViewAlignment.MiddleRight;
雖然我相信個別單元格樣式將覆蓋此。
3
我知道這是一個老問題,但正如其他人所說,DataGridViewCell
和DataGridViewColumn
沒有RightToLeft
屬性。不過,也有方法可以解決該問題:
處理的
CellPainting
事件並使用TextFormatFlags.RightToLeft
標誌:(代碼從CodeProject question拍攝)private void RTLColumnsDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == RTLColumnID && e.RowIndex >= 0) { e.PaintBackground(e.CellBounds, true); TextRenderer.DrawText(e.Graphics, e.FormattedValue.ToString(), e.CellStyle.Font, e.CellBounds, e.CellStyle.ForeColor, TextFormatFlags.RightToLeft | TextFormatFlags.Right); e.Handled = true; } }
如果這只是一個特定的您可能會嘗試在單元格內容的開頭插入不可見的RTL character(U + 200F)。
1
就這麼簡單:
DataGridView1.Columns["name of column"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
0
我知道這是一個很老的文章,但很多時候我已經找到答案,舊的文章,就像有幫助的指點一個解決方案,所以我會發布我的解決方案。
我通過處理datagridview的EditingControlShowing事件來做到這一點。解決這個問題時拋出我的一件事是,我試圖在datagridviewcell中查找屬性RightToLeft,但是這是Textbox的屬性。
private void MyDataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox currentCell = e.Control as TextBox;
if (currentCell != null
&& myDataGridView.CurrentCell.ColumnIndex == NameOfYourColumn.Index) //or compare using column name
{
currentCell.RightToLeft = RightToLeft.Yes;
}
}
相關問題
- 1. 在setter方法中設置字符串
- 2. 如何在liferay portal嚮導中設置JDBC連接字符串?
- 3. 如何在選項[字符串]中設置字符串?
- 4. 如何從字符串中設置Border.BorderBrush
- 5. 如何在android中設置字符串字符編碼
- 6. 如何在Python字符串中設置字符?
- 7. 字符串&字符串的設置值
- 8. 如何設置字符串中的字符數量?
- 9. 如何在Android中的EditText中設置字符串的芯片
- 10. 如何在Xamarin.Forms中設置ContentPage方向
- 11. 如何在nativescript中設置方向
- 12. 了setString(0,字符串)不設置在java中的字符串
- 13. Swift在字符串中設置字符串的顏色
- 14. 如何在MIPS中設置一個指向一個asciiz字符串的指針
- 15. 在Matlab中設置字符串搜索,如果找不到任何字符串,如何跳過字符串?
- 16. 設置DataGridViewCell的錯誤圖標位置
- 17. 如何在c#中查詢設置字符串中的值?
- 18. 如何找到字符串放在字符串中的位置?
- 19. 如何在.net中以編程方式設置連接字符串配置?
- 20. 如何在android中設置SlidingTabLayout中字符串的上方圖標?
- 21. 設置字符串
- 22. 如何在phpmyadmin中將字符串字段設置爲NULL?
- 23. 如何設置字符串使一類的Python方法
- 24. 限制DataGridViewCell中的字符數
- 25. preg_replace,如何設置字符串
- 26. 如何設置變量爲字符串?
- 27. 如何在C#中找到字符串的第一個強方向性字符?
- 28. Android:如何在我的字符串中設置小寫字母的子串?
- 29. 如何在我的豬腳本中設置多行字符串?
- 30. 如何在Spring Boot中解碼由@RequestParam設置的字符串?
我需要設置方向不對齊的單元格 – mbmsit 2011-02-17 09:50:48
這是什麼意思?我不確定我是否理解這個區別。正如我的答案所解釋的,您不能爲單個單元格設置RightToLeft屬性;它只適用於整個控制。它是爲使用從右到左的字體的區域設計的,在這種情況下,屏幕上的所有內容都需要從右到左,而不僅僅是一個特定的單元格。 「方向」與「對齊」有何不同? – 2011-02-19 04:35:05