Devexpress未绑定列显示文本

时间:2015-02-21 11:21:12

标签: vb.net devexpress

我从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

1 个答案:

答案 0 :(得分:0)

您应该将UnboundTypedoc)和FormatTypedoc)设置为适当的值:

...
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
...