开发者

C# datagrid edit cells MVVM

public DataView VariationGrid
    {
        get
        {
            if (_vargrid != null)
            {
                return _vargrid;
            }
            else
            {
                DataTable data = new DataTable();


                #region Columns
                foreach (var param in SelQuestion.QuestionParameters)
                {
                    DataColumn datac = new DataColumn(param.Name);
                    data.Columns.Add(datac);
                }
                #endregion

                #region Rows

                foreach (Variation variation in SelQuestion.Variations)
                {
                    DataRow datarow = data.NewRow();
                    foreach (var parameter in variation.QuestionParameters)
                    {

                        datarow[parameter.Key.Name] = parameter.Value;

                    }
                    data.Rows.Add(datarow);

                }
               开发者_如何学编程 #endregion
                return data.DefaultView;
            }

        }
        set
        {
            _vargrid = value;
            RaisePropertyChanged("VariationGrid");
        }



    }

This is how I made my ItemsSource of the DataGrid... So as you can see every row is a different Variation and every column are QuestionParameters.

This is how I Bind this to my DataGrid:

<DataGrid SelectedIndex="{Binding Path=SelectedRow}" ItemsSource="{Binding Path=VariationGrid}"  AutoGenerateColumns="True" Height="153" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dataGrid3" VerticalAlignment="Top" Width="301" >

Now is my question:

When I edit a cell, it needs to change the value of the questionparameter of the variation which I have selected. How do I do this, because I have now idea...


You might be better off creating an object graph to bind your data grid to and then have that object graph bubble up changed events (via INotifyPropertyChanged) that you can pay attention to in your view model.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜