M
M
Michael2021-06-15 15:13:44
WPF
Michael, 2021-06-15 15:13:44

How to update view when adding column to DataGrid?

Hello.
There is a table

<DataGrid ItemsSource="{Binding DataView, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

This table gets UserName from another table
private DataView _dataView;
        public DataView DataView
        {
            get => _dataView; 
            set
            {
                _dataView = value;
                NotifyPropertyChanged();
            }
        }

        public DelegateCommand<object> CmdUserCellEdit => new DelegateCommand<object>(arg =>
        {
            var cell = arg as DataGridCellEditEndingEventArgs;

            if (cell.Column.SortMemberPath == "UserName")
            {
                var tb = cell.EditingElement as TextBox;
                string tbText = tb.Text.ToString();

                DataView.Table.Columns.Add(tbText);


            }
        });

In the debugger, I see that the columns are added, but the view is not updated. How to update it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-06-16
@yarosroman

Add a column to the DataGrid. Because DataView is a layer between the data and the grid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question