WPF RadGridView OnCellEditEnded with Custom column NewData and OldData are always empty

1 Answer 51 Views
GridView
Shukurdin
Top achievements
Rank 1
Shukurdin asked on 17 Jun 2024, 07:03 AM
We have the similar problem on 2024.1.228.45
https://www.telerik.com/forums/gridview-celleditended-returns-null-data-properties-for-custom-column

Is there any solution to get NewData and OldData on OncellEditEnded for a custom column?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Jun 2024, 09:48 AM

Hello Shukurdin,

To make the NewData property of the event args work as expected, you will need to override the GetNewValueFromEditor method of the custom column.

public class GridViewCustomColumn : GridViewDataColumn
{
     // other code here

    public override object GetNewValueFromEditor(object editor)
    {
        var textBox = (TextBox)editor;
        return textBox.Text;
    }
} 

To make the OldValue work, you will need to bind the Value property to the DataMemberBinding.

  public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
  {
      var textBlock = cell.Content as TextBlock;

      if (textBlock == null)
      {
          textBlock = new TextBlock();
          textBlock.SetBinding(TextBlock.TextProperty, this.DataMemberBinding);
          cell.Content = textBlock;
      }
      cell.SetBinding(GridViewCell.ValueProperty, DataMemberBinding);      
      return textBlock;
  }

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Shukurdin
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or