0
votes

I take this example from https://documentation.devexpress.com/#WindowsForms/CustomDocument1477

Now if you look the example you will see that in unbound column values are numeric. How can i do this with text data, if table have string data.

  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

1 Answers

0
votes

You should set UnboundType (doc) and FormatType (doc) to appropriate value:

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