user3014908
user3014908

Reputation: 3

WPF INotifyPropertyChanged not allowing null value

Using WPF and EF and new to both. I may use the wrong terminology.

Using the EF wizard and code generators, I set up an EF using several tables, one of which is a lookup table.

I set up a form with a datagrid for the user to edit items in this lookup table. An issue I'm having is that the user can edit a cell, then close the form, but the editing of the cell will not update the underlying SQL database. I researched INotifyPropertyChanged and it seemed to be what I needed.

I implemented INotifyPropertyChanged to class bound to the datagrid. Before the implementation, the datagrid displayed all null values. After implementation, a message displays when the first null value is read that a nullable object must have a value.

Code:

    Public Property ProcedureName As String
    Get
        Return _ProcedureName
    End Get
    Set(value As String)
        _ProcedureName = value
        RaisePropertyChanged("ProcedureName")
    End Set
End Property
Private _ProcedureName As String

The exception occurs at "_ProcedureName = value".

Entire class:

Imports System

Imports System.Collections.ObjectModel

Partial Public Class tlkpProcedures_PartB Inherits PropertyChangedBase Public Property CPT As String Get Return _CPT End Get Set(value As String) _CPT = value RaisePropertyChanged("CPT") End Set End Property Private _CPT As String Public Property ProcedureName As String Get Return _ProcedureName End Get Set(value As String) _ProcedureName = value RaisePropertyChanged("ProcedureName") End Set End Property Private _ProcedureName As String

Public Property BillingAmount As Nullable(Of Decimal)
    Get
        Return _BillingAmount
    End Get
    Set(value As Nullable(Of Decimal))
        _BillingAmount = value
        RaisePropertyChanged("BillingAmount")
    End Set
End Property
Private _BillingAmount As Decimal
Public Property UniqueID As Integer

Public Overridable Property tblBilling_PartB As ObservableCollection(Of tblBilling_PartB) = New ObservableCollection(Of tblBilling_PartB)

End Class

Any help or advice is appreciated.

Upvotes: 0

Views: 175

Answers (1)

franssu
franssu

Reputation: 2430

I'm not very good at VB but it seems like you try to assign a Nullable ( value As Nullable(Of Decimal) ) to a non-nullable (Private _BillingAmount As Decimal).

You should either cast value as Decimal or define _BillingAmount as Nullable(Of Decimal).

Upvotes: 0

Related Questions