Completed
Last Updated: 02 Aug 2016 06:48 by ADMIN
ADMIN
Hristo
Created on: 20 Jul 2016 11:49
Category: GridView
Type: Bug Report
0
FIX. RadGridView - incorrect excel-like filtering in GridViewDecimalColumn for values with many decimal places
How to reproduce:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetSampleData();
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.EnableFiltering = true;
        this.radGridView1.ShowFilteringRow = false;
        this.radGridView1.ShowHeaderCellButtons = true;
    }

    private DataTable GetSampleData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(double));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("IsValid", typeof(bool));
        dt.Columns.Add("Date", typeof(DateTime));

        for (int i = 0; i < 115; i++)
        {
            dt.Rows.Add(((double)i * 5 / 7) * 3, "Name " + i, i % 2 == 0, DateTime.Now.AddDays(i));
        }

        return dt;
    }
}

Workaround specify decimal as the type of the column in the DataTable object or clone the DataTAble object and change the type of the column:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        DataTable dt = this.GetSampleData();
        DataTable dtCloned = dt.Clone();
        dtCloned.Columns[0].DataType = typeof(decimal);
        foreach (DataRow row in dt.Rows)
        {
            dtCloned.ImportRow(row);
        }

        this.radGridView1.DataSource = dtCloned;
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.EnableFiltering = true;
        this.radGridView1.ShowFilteringRow = false;
        this.radGridView1.ShowHeaderCellButtons = true;
    }

    private DataTable GetSampleData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(double));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("IsValid", typeof(bool));
        dt.Columns.Add("Date", typeof(DateTime));

        for (int i = 0; i < 115; i++)
        {
            dt.Rows.Add(((double)i * 5 / 7) * 3, "Name " + i, i % 2 == 0, DateTime.Now.AddDays(i));
        }

        return dt;
    }
}

(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments