Public Class NoEllipsisColumn
Inherits DataGridViewTextBoxColumn
Public Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell
Get
Return New NoEllipsisCell
End Get
Set(ByVal value As System.Windows.Forms.DataGridViewCell)
MyBase.CellTemplate = value
End Set
End Property
End Class
Public Class NoEllipsisCell
Inherits DataGridViewTextBoxCell
Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal cellState As System.Windows.Forms.DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
paintParts = paintParts And Not DataGridViewPaintParts.ContentForeground
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
Dim format As New StringFormat(StringFormatFlags.NoWrap)
format.LineAlignment = StringAlignment.Center
format.[B]Trimming [/B]= StringTrimming.Word 'or Character
Dim brush As New SolidBrush(cellStyle.ForeColor)
graphics.DrawString(formattedValue, cellStyle.Font, brush, cellBounds, format)
brush.Dispose()
format.Dispose()
End Sub
End Class