Question

I have a datagrid (A C1 datagrid, in this case) bound to a property in my View Model. The XAML for the datagrid looks like this:

        <c1:C1DataGrid 
            AutoGenerateColumns="False"
            IsReadOnly="False"
            Margin="5" Width="auto"
            MinWidth="250"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            Name="dgNotifAssign"
            CanUserAddRows="True" 
            ItemsSource="{Binding Path=notifCodeSubs.notification_configuration}"
            >


            <c1:C1DataGrid.Columns>
                <c1:DataGridTextColumn 
                    Binding="{Binding Path=user_id}" 
                    Header="Recipient" 
                    VerticalAlignment="Stretch"
                    SortMemberPath="user_id"  
                    >

The property that it is bound to, in my viewmodel, looks like this:

Public Property notifCodeSubs As dsPeruseFM
    Get
        If _notifCode Is Nothing Then
            _notifCode = New dsPeruseFM
        End If
        Return _notifCode
    End Get
    Set(ByVal value As dsPeruseFM)
        MsgBox("If you can see this, success!")
    End Set
End Property

In the codebehind I create an instance of the viewmodel and set the datacontext of the xaml to that instance, rather simple...

Dim vm As New ctrlAlertNotifyVM

As well as:

ctrlAlertNotifyXML.DataContext = vm

The above configuration compiles and reads data just fine. The grid is populated with all the correct data, etc. The problem comes when I try to add Mode=twoway to the ItemsSource on the datagrid. At that point VS2010 spits out the following error:

A TwoWay or OneWayToSource binding cannot work on the read-only property 'notification_configuration' of type 'PeruseFM.dsPeruseFM'.

I'm quite sure that all of my properties are read/write. And while the set command for this is nothing more than a message box at this point, it doesn't seem like I can even access that.

So the question is... has anybody ever encountered this issue before?

Update, response to question "What does notification_configuration look like?" from sixlettervariables:

Public Function codeChanged(Optional ByVal x As String = "")

    If _notifCode Is Nothing Then
        _notifCode = New dsPeruseFM
    End If
    taNotifSubs.fillNotifSubs(notifCode:=x, dataTable:=_notifCode.notification_configuration)
    Return _notifCode
End Function
Was it helpful?

Solution

You've shown us that notifCodeSubs is read/write, however, that is not the actual property you've bound to.

From this viewpoint, the error message is fairly self-explanatory:

...read-only property 'notification_configuration'...

Therefore you cannot apply TwoWay binding to that property as an ItemsSource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top