Completed
Last Updated: 12 Oct 2017 12:18 by ADMIN
ADMIN
Hristo
Created on: 11 Oct 2017 15:24
Category: GridView
Type: Bug Report
0
FIX. RadGridView - exception in the RadTimePickerElement when you set a DBNull.Value
How to reproduce:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.EditorRequired += RadGridView1_EditorRequired;
    }

    private void RadGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
    {
        if (this.radGridView1.CurrentColumn.Index == 0)
        {
            e.Editor = new RadTimePickerElement();
        }
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Date", typeof(DateTime));

        for (int i = 0; i < 20; i++)
        {
            DataRow r = dt.NewRow();
            dt.Rows.Add(r);
        }
        
        return dt;
    }
}

Workaround: the scenario is not completely valid as when handling the EditorRequiredEvent one should use the GridTimePickerEditor
1. Use the column`s EditorType property: 
((GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).EditorType = GridViewDateTimeEditorType.TimePicker
2. Alternatively, handle the event this way:
private void RadGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (this.radGridView1.CurrentColumn.Index == 0)
    {
        e.Editor = new GridTimePickerEditor();
    }
}
0 comments