wpfvb.netradgridview

String with apostrophe doubles when bound to property


I have a radgridview with a cell whose data may contain an apostrophe. When the row is selected, the row context is cast to a collection of public properties. This works well except for the cell with an apostrophe.

    Private Sub dgSelectOrder_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)

    Dim row = TryCast(sender, GridViewRow)
    Dim selectedOrder = TryCast(row.DataContext, myProperties)

If the cell data has an apostrophe, for example LET'S GO, the property returns the value LET''S GO. The apostrophe is doubled. If that data gets saved back to the database, then retrieved again, the property returns LET''''S GO.

How do I cast the row data correctly?

Public Class myProperties

    Public Property pProjectNbr As String = String.Empty

Thanks.


Solution

  • I shouldn't have to do this but it's the only way it would work. I have similar code to cast the row.datacontext elsewhere. And that code runs as expected with the apostrophe.

        Private Sub dgArchivedOrders_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
    
            Dim row = TryCast(sender, GridViewRow)
            Dim selectedOrder = TryCast(row.DataContext, myProperties)
    
            If selectedOrder.pProjectNbr.Contains("''") Then
                Dim convertThis As String = selectedOrder.pProjectNbr
                selectedOrder.pProjectNbr = convertThis.Replace("''", "'")
            End If