我的数据库中有一个列项目代码,我已绑定到数据网格视图。项目代码采用这种格式“ABC”,我只想显示代码的“B”部分,我已将此列绑定到 gridview,现在希望让它显示子字符串。我尝试了 defaultcellstyle.format 但不知道如何为其获取子字符串。
问问题
3222 次
2 回答
2
是否可以向绑定对象添加新属性,例如 ItemCodePart,它返回项目代码的中间部分,然后将此属性绑定到列而不是项目代码?那将是最简单的方法。
另一种选择是处理 DataGridView 的 CellFormatting 事件并将 e.Value 设置为您要显示的项目代码部分:
Private Sub myDataGridView_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles myDataGridView.CellFormatting
If e.ColumnIndex = MyItemPartColumn.Index Then
Dim currentValue As String = CStr(myDataGridView.Item(e.ColumnIndex, e.RowIndex).Value)
Dim parts As String() = currentValue.Split(New Char() {"-"c})
e.Value = parts(1)
End If
End Sub
于 2009-08-25T17:47:43.037 回答
0
RowDataBound 事件 - 您可以编辑该字段的文本。
于 2009-08-25T17:51:00.330 回答