WPF DataGrid“单元格式等效项”
我正在尝试从 WinForms 转换为 WPF,并且在使用 DataGridView -> 时遇到了一些困难WPF 数据网格。
我已经很好地加载了所有数据,只是停留在单元格格式上。
有一个包含数字的列,但是如果数字为零,而不是显示 0,我希望它显示 NIL。
使用 DataGridView,下面的方法有效
Private Sub SampleDGV_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles SampleDGV.CellFormatting
Try
If e.RowIndex >= 0 And e.ColumnIndex = SampleDGV.Columns(CostColumn.Name).Index Then
If CDec(e.Value.ToString) = 0 Then
e.Value = "NIL"
e.FormattingApplied = True
End If
End If
Catch ex As Exception
End Try
End Sub
但现在我对 WPF 的等效项感到困惑
I'm trying to convert from WinForms to WPF and am struggling a bit with DataGridView -> WPF DataGrid.
I've got all the data loading nicely, just stuck on the cell formatting.
There is a column with numbers, however if the number is zero, rather than show 0, I'd like it to display NIL.
With DataGridView, the below worked
Private Sub SampleDGV_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles SampleDGV.CellFormatting
Try
If e.RowIndex >= 0 And e.ColumnIndex = SampleDGV.Columns(CostColumn.Name).Index Then
If CDec(e.Value.ToString) = 0 Then
e.Value = "NIL"
e.FormattingApplied = True
End If
End If
Catch ex As Exception
End Try
End Sub
But now I'm stumped on the WPF equivalent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否有一种简单的方法可以做到这一点,我会这样做,这似乎确实有效:
使用自定义转换器定义自定义列:
I am not sure if there is an easy way to do this, i'd do it like this which does seem to work:
Define a custom column with a custom converter: