This is a migrated thread and some comments may be shown as answers.

Update GridViewCell Value in UI in Edit Mode

2 Answers 29 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Veteran
Anton asked on 19 Feb 2021, 06:28 AM

Hello.

I need update value of RadGridView GridViewCell then she in Edit Mode.

I use MainGrid.BeginningEdit event:

private void MainGridOnBeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs args)
        {
            if(args == null || args.Cell.Value != null) return;

            if (BeginningCellEditEvent != null)
                BeginningCellEditEvent.Invoke(args);
        }

In BeginningCellEditEvent handler i try set new cell value:

private void ActivityDateFactTable_OnBeginningCellEditEvent(GridViewBeginningEditRoutedEventArgs args)
        {
            if((args?.Cell == null || args.Cell.Value != null)) return;
            if(!(args.Row.DataContext is ViewModel viewModel)) return;

            var bindingPath = args.Cell.DataColumn.DataMemberBinding.Path
                                                                            .Path
                                                                            .Replace("[", "")
                                                                            .Replace("]", "")
                                                                            .Split('_');
            if(bindingPath.Length < 3) return;            
            var calcValue = viewModel.GetCalculatedValue(bindingPath[0]);
            if (calcValue != null)
            {                
                args.Cell.Value = calcValue;                
                args.Cell.UpdateLayout();
            }
        }

or

private void ActivityDateFactTable_OnBeginningCellEditEvent(GridViewBeginningEditRoutedEventArgs args)
        {
            if((args?.Cell == null || args.Cell.Value != null)) return;
            if(!(args.Row.DataContext is ViewModel viewModel)) return;

            var bindingPath = args.Cell.DataColumn.DataMemberBinding.Path
                                                                            .Path
                                                                            .Replace("[", "")
                                                                            .Replace("]", "")
                                                                            .Split('_');
            if(bindingPath.Length < 3) return;            
            var calcValue = viewModel.GetCalculatedValue(bindingPath[0]);
            if (calcValue != null)
            {    
                this.Dispatcher.BeginInvoke
                ((Action) delegate
                    {
                        args.Cell.Value = calcValue;
                        args.Cell.UpdateLayout();                   
                    }
                );
            }
        }

Cell.Value is changed, but in UI not updated (as seen on screenshot).

How i can update value in UI after changing him in code and i need that cell stays in edit mode?

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 23 Feb 2021, 11:58 AM

Hello Anton,

You can update the initial value of the editing element in the following manner:

            if (calcValue != null)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    var tb = args.Cell.GetEditingElement() as TextBox;
                    tb.Loaded += (s, e) =>
                    {
                        tb.Text = calcValue.ToString();
                        tb.SelectAll();
                    };
                }));
            }

Please note that this will only work for columns that create a TextBox as their editing element and you may need to handle other types of editing controls respectively.

Do let me know if such an approach works for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Anton
Top achievements
Rank 1
Veteran
answered on 24 Feb 2021, 06:39 AM
[quote]Dilyan Traykov said:

Hello Anton,

You can update the initial value of the editing element in the following manner:

 

            if (calcValue != null)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    var tb = args.Cell.GetEditingElement() as TextBox;
                    tb.Loaded += (s, e) =>
                    {
                        tb.Text = calcValue.ToString();
                        tb.SelectAll();
                    };
                }));
            }

 

Please note that this will only work for columns that create a TextBox as their editing element and you may need to handle other types of editing controls respectively.

Do let me know if such an approach works for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

[/quote]

Hello.

This work fine, thank you!

Tags
GridView
Asked by
Anton
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
Anton
Top achievements
Rank 1
Veteran
Share this question
or