当单元格内容被截断时,将三个点(省略号)(...)更改为VB.Net DataGridView中的自定义字符 [英] Change the three dots (ellipses) (...) to custom characters in VB.Net DataGridView when cell content is truncated

查看:201
本文介绍了当单元格内容被截断时,将三个点(省略号)(...)更改为VB.Net DataGridView中的自定义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VB.Net中开发一个项目,我使用古吉拉特字体(非Unicode)。



我已经放置了一个DaraGridView(DGV)并显示数据存储在DGV中的数据。



在DGV中,如果单元格的内容被截断,则DGV显示椭圆(三点)(...);但是当字体设置为古吉拉特文字体时,它会显示古吉拉第字母ઈઈઈ而不是...,因为古吉拉特语字符ઈ用英文。编码。 (点)字符。



在古吉拉特语字体中,。可以用英文字符P生成。



那么,如何将椭圆更改为英文P字符? OR如何完全删除椭圆?



我已经在2010年8月31日星期二找到了类似的解决方案1:33 PM:
http://social.msdn.microsoft .com /论坛/ en-US / winforms / thread / 95c8963f-9832-4e2d-b057-3590afe3b65d



但我不知道这是完美的和/或这样做的唯一方法,它会真的有效。
如果在MSDN的上述链接上的解决方案是好的,从我可以删除多少代码和/或将需要更多的代码,使其充分发挥作用?

解决方案

您可以覆盖 CellFormatting 事件:

  Private Sub DGV_CellFormatting(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs)处理DGV.CellFormatting 
'检查空值
If(e Is Nothing)OrElse(e.Value Is Nothing )然后返回
'获取当前单元格
Dim C = DirectCast(sender,DataGridView).Rows(e.RowIndex).Cells(e.ColumnIndex)
'我不知道是否它的我的测试台或什么,但偶尔我在这里得到NULL,所以检查
如果(C不是)然后返回

'测量字符串,如果它适合,使用它是
如果TextRenderer.MeasureText(e.Value.ToString(),C.InheritedStyle.Font).Width< = C.Size.Width然后返回

'这是我们要附加的文本到字符串的末尾
Dim RepText =PPP
'这是我们的文本,我们将慢慢地删除最后一个字符,直到它符合
Dim NewText As String = e。价值

'循环直到我们的文字适合。注意:您可能必须在这里考虑单元格填充
Do While TextRenderer.MeasureText(NewText& RepText,C.InheritedStyle.Font).Width> = C.Size.Width
'关闭最后一个字符并重复
NewText = NewText.Substring(0,NewText.Length - 2)
循环

'设置新单元格的值
e。 Value = NewText& RepText
'标记我们已更改单元格的文本
e.FormattingApplied = True
End Sub


I am developing a project in VB.Net and I am using Gujarati fonts (non-Unicode).

I have placed a DaraGridView (DGV) and displaying the data stored in database in DGV.

In DGV, if the contents of the cell is truncated, the DGV shows ellipses (three dots) (...); but as the font is set to a Gujarati font, it displays a Gujarati alphabet "ઈઈઈ" instead of "..." because the Gujarati character "ઈ" is coded with the English "." (dot) character.

In Gujarati font, "." can be generated with the English character "P".

So, How can I change the ellipses to English "P" character? OR How can I remove the ellipses completely?

I have found a similar solution by berc on Tuesday, August 31, 2010 1:33 PM : http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/95c8963f-9832-4e2d-b057-3590afe3b65d

but I am not sure it is the perfect and/or the only way to do so, AND it will really work or not. If the solution on the above link of MSDN is fine, how much code from it I can remove and/or will I need more code to get it work fully?

解决方案

You can override the CellFormatting event:

Private Sub DGV_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DGV.CellFormatting
    'Check for null values
    If (e Is Nothing) OrElse (e.Value Is Nothing) Then Return
    'Grab the current cell
    Dim C = DirectCast(sender, DataGridView).Rows(e.RowIndex).Cells(e.ColumnIndex)
    'I'm not sure if its my testbed or what but occasionally I was getting NULL here so check for that
    If (C Is Nothing) Then Return

    'Measure the string, if it fits, use it as is
    If TextRenderer.MeasureText(e.Value.ToString(), C.InheritedStyle.Font).Width <= C.Size.Width Then Return

    'This is our text that we'd like to append to the end of the string
    Dim RepText = "PPP"
    'This is our text that we'll slowly take off the last character of until it fits
    Dim NewText As String = e.Value

    'Loop until our text fits. NOTE: You may have to take into account cell padding here, too
    Do While TextRenderer.MeasureText(NewText & RepText, C.InheritedStyle.Font).Width >= C.Size.Width
        'Chop the last character off and repeat
        NewText = NewText.Substring(0, NewText.Length - 2)
    Loop

    'Set the new cell's value
    e.Value = NewText & RepText
    'Flag that we've changed the cell's text
    e.FormattingApplied = True
End Sub

这篇关于当单元格内容被截断时,将三个点(省略号)(...)更改为VB.Net DataGridView中的自定义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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