Unplanned
Last Updated: 08 Jul 2021 06:02 by ADMIN
Amit
Created on: 08 Jul 2021 06:02
Category: PivotGrid
Type: Bug Report
1
RadPivotGrid getting Error Message - An item with the same key has already been added

When defining more than 11 PivotGridColumnField(s), an error is thrown: "An item with the same key has already been added."

Set up to reproduce:

<telerik:RadPivotGrid ID="RadPivotGrid1" runat="server" EmptyValue="No data" AllowPaging="true" PageSize="10"
    OnNeedDataSource="RadPivotGrid1_NeedDataSource">
    <Fields>
        <telerik:PivotGridRowField DataField="ShipCountry" UniqueName="ShipCountry">
        </telerik:PivotGridRowField>

        <telerik:PivotGridAggregateField DataField="Freight" UniqueName="Freight">
        </telerik:PivotGridAggregateField>

        <telerik:PivotGridColumnField DataField="ShipCountry1" UniqueName="ShipCountry1"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry2" UniqueName="ShipCountry2"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry3" UniqueName="ShipCountry3"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry4" UniqueName="ShipCountry4"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry5" UniqueName="ShipCountry5"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry6" UniqueName="ShipCountry6"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry7" UniqueName="ShipCountry7"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry8" UniqueName="ShipCountry8"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry9" UniqueName="ShipCountry9"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry10" UniqueName="ShipCountry10"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry11" UniqueName="ShipCountry11"></telerik:PivotGridColumnField>
        <telerik:PivotGridColumnField DataField="ShipCountry12" UniqueName="ShipCountry12"></telerik:PivotGridColumnField>
    </Fields>
</telerik:RadPivotGrid>

C#

protected void RadPivotGrid1_NeedDataSource(object sender, PivotGridNeedDataSourceEventArgs e)
{
    (sender as RadPivotGrid).DataSource = OrdersTable();
}

private DataTable OrdersTable()
{
    DataTable dt = new DataTable();

    dt.Columns.Add(new DataColumn("OrderID", typeof(int)));
    dt.Columns.Add(new DataColumn("OrderDate", typeof(DateTime)));
    dt.Columns.Add(new DataColumn("Freight", typeof(decimal)));
    dt.Columns.Add(new DataColumn("ShipCountry", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry1", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry2", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry3", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry4", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry5", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry6", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry7", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry8", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry9", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry10", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry11", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry12", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry13", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry14", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry15", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry16", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry17", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry18", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry19", typeof(string)));
    dt.Columns.Add(new DataColumn("ShipCountry20", typeof(string)));

    dt.PrimaryKey = new DataColumn[] { dt.Columns["OrderID"] };

    for (int i = 0; i < 70; i++)
    {
        int index = i + 1;

        DataRow row = dt.NewRow();

        row["OrderID"] = index;
        row["OrderDate"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).AddHours(index);
        row["Freight"] = index * 0.1 + index * 0.01;
        row["ShipCountry"] = "Country " + index;
        row["ShipCountry1"] = "Country " + index;
        row["ShipCountry2"] = "Country " + index;
        row["ShipCountry3"] = "Country " + index;
        row["ShipCountry4"] = "Country " + index;
        row["ShipCountry5"] = "Country " + index;
        row["ShipCountry6"] = "Country " + index;
        row["ShipCountry7"] = "Country " + index;
        row["ShipCountry8"] = "Country " + index;
        row["ShipCountry9"] = "Country " + index;
        row["ShipCountry10"] = "Country " + index;
        row["ShipCountry11"] = "Country " + index;
        row["ShipCountry12"] = "Country " + index;
        row["ShipCountry13"] = "Country " + index;
        row["ShipCountry14"] = "Country " + index;
        row["ShipCountry15"] = "Country " + index;
        row["ShipCountry16"] = "Country " + index;
        row["ShipCountry17"] = "Country " + index;
        row["ShipCountry18"] = "Country " + index;
        row["ShipCountry19"] = "Country " + index;
        row["ShipCountry20"] = "Country " + index;

        dt.Rows.Add(row);
    }

    return dt;
}

 

0 comments