DataGridView.RowTemplate.DefaultCellStyle.WrapMode

0
0

Hi Wisej,

When setting DataGridView.RowTemplate.DefaultCellStyle.WrapMode=True, Default Column.DefaultCellStyle.NullValue = True not active.

Why is it?

Best regards.

  • You must to post comments
0
0

It’s a bug. When you set the Me.DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True it initializes the Me.DataGridView1.DefaultCellStyle and when inheriting the cell style it end up overriding (incorrectly) the column’s CellStyle only for the NullValue. Logged as #2349.

Two workarounds:

  1. Create a custom cell and column
Public Class MyDataGridViewCheckBoxCell
 Inherits DataGridViewCheckBoxCell

 Public Overrides Function GetInheritedStyle(includeVisualProperties As Boolean) As DataGridViewCellStyle

 Dim style = MyBase.GetInheritedStyle(includeVisualProperties)
 style.NullValue = True
 Return style

 End Function

End Class

Public Class MyDataGridViewCheckBoxColumn
 Inherits DataGridViewCheckBoxColumn

 Public Sub New()
 MyBase.New(New MyDataGridViewCheckBoxCell)
 End Sub

End Class


2. Create a custom cell and assign it:

Public Class MyDataGridViewCheckBoxCell
 Inherits DataGridViewCheckBoxCell

 Public Overrides Function GetInheritedStyle(includeVisualProperties As Boolean) As DataGridViewCellStyle

 Dim style = MyBase.GetInheritedStyle(includeVisualProperties)
 style.NullValue = True
 Return style

 End Function

End Class

Me.DataGridView1.Columns(2).CellTemplate = New MyDataGridViewCheckBoxCell
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.