views:

72

answers:

1

I am using teleriks gridview in an mvvm silverlight project. I am struggling to get the editing of a row working. If I double click a cell I am able to change the text of that row. I have a command for a save button. but when I look at my ObservableCollection prog I do not see the changes. so I went and changed everything from observableCollection to just a generic list and now im struggling binding the data to the grid. With the observable collection I am able to initially bind the data to the grid.

    private ObservableCollection<Program> _programResults;
    public ObservableCollection<Program> ProgramResults
    {
        get { return _programResults; }
        set { SetObject(ref _programResults, value, "ProgramResults"); }
    }

<telerik:RadGridView Margin="5,5,5,5" ShowGroupPanel="False" Height="300" ItemsSource="{Binding ProgramResults, Mode=TwoWay}" SelectedItem="{Binding SelectedProgram, Mode=TwoWay}" AutoGenerateColumns="False" VerticalAlignment="Top">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Program ID" DataMemberBinding="{Binding ProgramResults.ProgramID}" MinWidth="300"></telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Program Name" DataMemberBinding="{Binding Name}" MinWidth="300"></telerik:GridViewDataColumn>                       
            </telerik:RadGridView>
A: 

gevjen,

The first problem I see that is going to prevent your collection from updating is that your binding is only one way. Try something like this.

Now you'll probably won't to come up with some way to decide what records changed when Save is collected.

Maybe create a Collection in your ViewModel and on your set of each of your SelectedProgram objects, insert the Id into that collection and then loop through this collection when Save is fired and update those records.

These are suggestions for the ObservableCollection. You'll need to make sure your objects implement INPC. Check the Output window for databinding errors if you are having problems.

frosty