【问题标题】:Devexpress unbound column display textDevexpress 未绑定列显示文本
【发布时间】:2015-02-21 19:26:43
【问题描述】:

这个例子来自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

【问题讨论】:

    标签: vb.net devexpress


    【解决方案1】:

    您应该将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
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2016-04-24
      相关资源
      最近更新 更多