Articles in this section
Category / Section

How to load null value to the GridDateTimeColumn when AllowInlineEditing is set to true in WinRT DataGrid?

4 mins read

The SfDatePicker is loaded as UIElement of the GridDateTimeColumn in edit mode. By default, old value is replaced when you try to commit the blank value on editing and when the SfDatePicker.AllowInlineEditing property is enabled.

You can overcome this by deriving a new class from the GridCellDateTimeRenderer and overriding the OnEditElementLoaded virtual method. In this method, you can get the corresponding editor, SfDatePicker of the GridDateTimeColumn and you can explicitly set the SfDatePicker.Value as null in SfTextBoxExt.TextChanged event.

The SfTextBoxExt is loaded as editor of the SfDatePicker control.

 

C#

public class GridCellDateTimeRendererExt : GridCellDateTimeRenderer

{

    SfDatePicker datepicker = null;

    protected override void OnEditElementLoaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)

    {

        datepicker = (SfDatePicker)sender;

        //Gets the SfTextBoxExt editor loaded in the SfDatePicker

        SfTextBoxExt textBox = ((SfDatePicker)sender).FindDescendantByName("PART_TextBoxExt") as SfTextBoxExt;

       //TextChanged event of SfTextBoxExt is wired

        textBox.TextChanged += textBox_TextChanged;

        base.OnEditElementLoaded(sender, e);

    }

           void textBox_TextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e)

    {

        var text = sender as SfTextBoxExt;

        if (text.Text == string.Empty && datepicker.AllowInlineEditing)

        {

         //Sets null to value of SfDatePicker expilicitly

            datepicker.SetValue(SfDatePicker.ValueProperty, null);

        } 

    }             

}

In the above code example, FindDescendantByName is an extension helper method available in a attached sample.

 


 

Refer to the following code example to remove the default GridCellDateTimeRenderer and add the customized GridCellDateTimeRendererExt to the SfDataGrid.CellRenderer collection.

C#

public MainPage()
{
    this.InitializeComponent();
    //Customized renderer is added to CellRenderers collection 
    this.grid.CellRenderers.Remove("DateTime");
    this.grid.CellRenderers.Add("DateTime", new GridCellDateTimeRendererExt());
}

Sample Links:

WinRT: https://www.syncfusion.com/downloads/support/directtrac/141421/ze/WinRT2074283480

WP: https://www.syncfusion.com/downloads/support/directtrac/141421/ze/WindowsPhone-1688298690

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied