Completed
Last Updated: 20 Oct 2015 08:37 by ADMIN
ADMIN
Dimitar
Created on: 12 Aug 2015 09:42
Category: GridView
Type: Bug Report
0
FIX. RadGridView - when the FreeFormDateTime mask type is used with the RadDateTimeEditor the value is not initialized correctly.
To reproduce:
- Use this code:
private void Form1_Load(object sender, EventArgs e)
{
    CenterToParent();

    radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;

    GridViewTextBoxColumn columnName = new GridViewTextBoxColumn();
    columnName.Name = "Name";
    columnName.HeaderText = "Name";
    columnName.FieldName = "Name";
    columnName.MaxLength = 50;
    columnName.Width = 200;
    columnName.TextAlignment = ContentAlignment.MiddleLeft;
    radGridView1.MasterTemplate.Columns.Add(columnName);

    GridViewDateTimeColumn columnDate = new GridViewDateTimeColumn();
    columnDate.Name = "Date";
    columnDate.HeaderText = "Date";
    columnDate.FieldName = "Date";
    columnDate.Format = DateTimePickerFormat.Custom;
    columnDate.CustomFormat = "MM/dd/yyyy";
    columnDate.FormatString = "{0:MM/dd/yyyy}";
    columnDate.NullValue = null;
    columnDate.Width = 100;
    this.radGridView1.Columns.Add(columnDate);

    radGridView1.Rows.Add("Row 1", null);
    radGridView1.Rows.Add("Row 2", null);
    radGridView1.Rows.Add("Row 3", null);
    radGridView1.Rows.Add("Row 4", null);
}

void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    if (e.ActiveEditor is RadDateTimeEditor)
    {
        ((RadDateTimePickerElement)((RadDateTimeEditor)e.ActiveEditor).EditorElement).TextBoxElement.MaskType = MaskType.FreeFormDateTime;
      
    }
}

- Start the application and star edition date time value. You will notice that the editor value is initialized incorrectly. This occurs only when the cell is edited for the firs time.

Workaround:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    if (e.ActiveEditor is RadDateTimeEditor)
    {
        ((RadDateTimePickerElement)((RadDateTimeEditor)e.ActiveEditor).EditorElement).TextBoxElement.MaskType = MaskType.FreeFormDateTime;
        e.ActiveEditor.Value = radGridView1.CurrentCell.Value;
    }
}
0 comments