DataGridViewX编辑控件中由DotNetBar提供的编辑控件不支持CellFormatting事件
如题,由于DotNetBar提供的编辑控件不支持CellFormatting事件,所以如想要在由DotNetBar的编辑控件中控制显示格式,则无法实现
控制编辑时的格式,则可以由EditingControlShowing事件实现,在此事件中,可以把e.Control对像转换成正确的编辑控件对像,然后进行格式控制,代码如下:
Private Sub xDataGridView_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles xDataGridView.EditingControlShowing
If (TypeOf e.Control Is DataGridViewDoubleInputEditingControl) Then
Dim pInput As DataGridViewDoubleInputEditingControl = CType(e.Control, DataGridViewDoubleInputEditingControl)
Dim pFormat As String = "F0" '默认值为无小数位数
Dim pRowIndex As Integer = xDataGridView.CurrentRow.Index
Dim pKeyName As String = mCurrentViewList(pRowIndex).fKey
pInput.DisplayFormat = MyHub.mModuleMain.mUnitManager.getCurrentDisplayFormat(getFieldUnitClass(pKeyName))
End If
End Sub
但编辑过后,正常显示时的格式则无法控制,由Microsoft原生提供的编辑控件,则可以通过CellFormatting事件,来单独控制显示格式,如代码:
Private Sub xDataGridView_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles xDataGridView.CellFormatting
If (e.ColumnIndex = xMinColumn.Index OrElse e.ColumnIndex = xSafeMinColumn.Index OrElse e.ColumnIndex = xSafeMaxColumn.Index OrElse e.ColumnIndex = xMaxColumn.Index) Then
If (e.RowIndex >= 0 AndAlso e.RowIndex < mCurrentViewList.Count) Then
Dim pKeyName As String = mCurrentViewList(e.RowIndex).fKey
e.CellStyle.Format = MyHub.mModuleMain.mUnitManager.getCurrentDisplayFormat(getFieldUnitClass(pKeyName))
End If
End If
End Sub