Completed
Last Updated: 27 Sep 2018 06:54 by Dimitar
ADMIN
Dimitar
Created on: 14 Sep 2018 06:40
Category: GridView
Type: Bug Report
1
FIX. RadGridView - the format of the column is not respected when using nullable DateTime
Use attached to reproduce.
- Open the data filter dialog from the excel-like filtering on the date column.
- The date time format in the editor is not respected.
- Consider the default cell editor as well.  

Workaround:

private void RadGridView1_CreateCompositeFilterDialog(object sender, GridViewCreateCompositeFilterDialogEventArgs e)
{
    var dialog = e.Dialog as CompositeDataFilterForm;
    dialog.DataFilter.EditorInitialized -= DataFilter_EditorInitialized;
    dialog.DataFilter.EditorInitialized += DataFilter_EditorInitialized;
 
    dialog.DataFilter.NodeFormatting -= DataFilter_NodeFormatting;
    dialog.DataFilter.NodeFormatting += DataFilter_NodeFormatting;
}
 
private void DataFilter_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    var criteriaNode = e.NodeElement as DataFilterCriteriaElement;
    if (criteriaNode != null)
    {
        var node = criteriaNode.Data as DataFilterCriteriaNode;
        if (node.DescriptorValue != null && node.PropertyName == "Date")
        {
            criteriaNode.ValueElement.Text = ((DateTime?)node.DescriptorValue).Value.ToString("MM/dd/yyyy");
        }
    }
}
 
private void DataFilter_EditorInitialized(object sender, TreeNodeEditorInitializedEventArgs e)
{
    var editor = e.Editor as TreeViewDateTimeEditor;
    if (editor != null)
    {
        var element = editor.EditorElement as BaseDateTimeEditorElement;
        element.Format = DateTimePickerFormat.Custom;
        element.CustomFormat = "dd/MM/yyyy";
    }
}
 
Attached Files:
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments