我从https://documentation.devexpress.com/#WindowsForms/CustomDocument1477
中提取此示例现在,如果您查看示例,您将看到未绑定的列值是数字。如果表有字符串数据,我怎么能用文本数据呢?
Private Sub Form1_Load(ByVal sender As System.Object(ByVal e As System.EventArgs) Handles MyBase.Load
gridControl1.ForceInitialize()
' Create an unbound column.
Dim unbColumn As GridColumn = GridView1.Columns.AddField("Total")
unbColumn.VisibleIndex = GridView1.Columns.Count
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal
' Disable editing.
unbColumn.OptionsColumn.AllowEdit = False
' Specify format settings.
unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
unbColumn.DisplayFormat.FormatString = "c"
' Customize the appearance settings.
unbColumn.AppearanceCell.BackColor = Color.LemonChiffon
End Sub
' Returns the total amount for a specific row.
Private Function getTotalValue(view As GridView, listSourceRowIndex As Integer) As Decimal
Dim unitPrice As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"))
Dim quantity As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity"))
Dim discount As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount"))
Return unitPrice * quantity * (1 - discount)
End Function
' Provides data for the Total column.
Private Sub GridView1_CustomUnboundColumnData(ByVal sender As Object,ByVal e As CustomColumnDataEventArgs) Handles GridView1.CustomUnboundColumnData
Dim view As GridView = TryCast(sender, GridView)
If e.Column.FieldName = "Total" AndAlso e.IsGetData Then
e.Value = getTotalValue(view, e.ListSourceRowIndex)
End If
End Sub
答案 0 :(得分:0)
您应该将UnboundType
(doc)和FormatType
(doc)设置为适当的值:
...
Dim unbColumn As GridColumn = GridView1.Columns.AddField("Total")
unbColumn.VisibleIndex = GridView1.Columns.Count
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.String
' Disable editing.
unbColumn.OptionsColumn.AllowEdit = False
' Specify format settings.
unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.None
...