开发者

telerik gridview in silverlight using mvvm

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 c开发者_开发知识库hanged 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>


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.

<telerik:GridViewDataColumn Header="Program Name" DataMemberBinding="{Binding Name, Mode=TwoWay}" MinWidth="300"></telerik:GridViewDataColumn>                        

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.


We have wound up using a dialog on a selected item and updating the data through another view. Getting the selected item through binding is easy enough and this seems to solve our problems

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜