Datagrid showing inline edit mode after adding a new item to the collection

0 Answers 41 Views
DataGrid
Carlos
Top achievements
Rank 1
Carlos asked on 12 Jul 2024, 12:08 AM

I have the datagrid UserEditMode set to "External", and somehow it keeps showing the inline edit mode/box. This happens as soon as I programmatically adda new item to the collection. Is there a way to stop this from happening? I'm looking for a way to hide that blue box and to just programmatically save the changes in the item as soon as any of the cells loses focus:

<telerikGrid:RadDataGrid ItemsSource="{x:Bind ViewModel.Parameters, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" UserEditMode="External" CanUserChooseColumns="False" UserFilterMode="Disabled" UserGroupMode="Disabled" UserSortMode="None">
    <telerikGrid:RadDataGrid.Columns>
        <telerikGrid:DataGridTextColumn PropertyName="Key" Header="Parameter"/>
        <telerikGrid:DataGridTextColumn PropertyName="Value" Header="Value"/>
        <telerikGrid:DataGridTextColumn PropertyName="Description" Header="Description"/>
    </telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>


using System.Collections.ObjectModel;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace App1.ViewModels;

public partial class MainViewModel : ObservableObject
{
    [ObservableProperty]
    public string? name;

    [ObservableProperty]
    public ObservableCollection<ParameterViewModel> parameters;

    public MainViewModel()
    {
        Parameters = new ObservableCollection<ParameterViewModel>();
        this.AddNewParameter();
    }    

    private void Parameter_PropertyChanged(object? sender, PropertyChangedEventArgs e)
    {
        var item = sender as ParameterViewModel;
        if (item is not null)
        {
            var index = Parameters.IndexOf(item);
            if (index == Parameters.Count - 1)
                AddNewParameter();
        }
    }

    public void AddNewParameter()
    {
        var Parameter = new ParameterViewModel() { Key = "", Value = "", Description = "" };
        Parameter.PropertyChanged += Parameter_PropertyChanged;
        Parameters.Add(Parameter);
    }
}
public partial class ParameterViewModel : ObservableRecipient
{
    [ObservableProperty]
    public string? key;
    [ObservableProperty]
    public string? value;
    [ObservableProperty]
    public string? description;
}

Dimitar
Telerik team
commented on 16 Jul 2024, 08:15 AM

Hi Carlos,

What library are you using for the ObservableObject and ObservableProperty? 

I have tried reproducing this by binding to the standard ObservableCollection but I can't reproduce it (see attached).  

Let me know if I am missing something in this case.

Carlos
Top achievements
Rank 1
commented on 17 Jul 2024, 05:07 PM

Hi Dimitar, thanks for reaching out.

I'm using CommunityToolkit.Mvvm 8.2.2:

CommunityToolkit.Mvvm.ComponentModel.ObservableObject

CommunityToolkit.Mvvm.ComponentModel.ObservableProperty

 

The following is the ObservableCollection I'm using:

System.Collections.ObjectModel.ObservableCollection

 

Thanks,

CM

Dimitar
Telerik team
commented on 18 Jul 2024, 08:40 AM

Hi Carlos,

Thanks for specifying that. I have created a test project using your code but still cannot reproduce this. I ahve attached the project. Can you please check it and let me know what I am missing? 

I am looking forward to your reply.

No answers yet. Maybe you can help?

Tags
DataGrid
Asked by
Carlos
Top achievements
Rank 1
Share this question
or